remove ^M characters from file using sed
Use tr: tr -d ‘^M’ < inputfile (Note that the ^M character can be input using Ctrl+VCtrl+M) EDIT: As suggested by Glenn Jackman, if you’re using bash, you could also say: tr -d $’\r’ < inputfile
Use tr: tr -d ‘^M’ < inputfile (Note that the ^M character can be input using Ctrl+VCtrl+M) EDIT: As suggested by Glenn Jackman, if you’re using bash, you could also say: tr -d $’\r’ < inputfile
I don’t know if it’s possible to do ranges in awk. You could do a for loop, but you would have to add handling to filter out the columns you don’t want. It’s probably easier to do this: awk -F, ‘{OFS=”,”;print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$20,$21,$22,$23,$24,$25,$30,$33}’ infile.csv > outfile.csv something else to consider – and this faster and more … Read more
If you’re looking for a particular string, put quotes around it: awk ‘$1 == “findtext” {print $3}’ Otherwise, awk will assume it’s a variable name.
This maybe what you’re looking for: awk ‘BEGIN {FS=” “;} {printf “‘\”%s’\” “, $1}’ That is, with ‘\” you close the opening ‘, then print a literal ‘ by escaping it and finally open the ‘ again.
sed -i ‘8i This is Line 8’ FILE inserts at line 8 This is Line 8 into file FILE -i does the modification directly to file FILE, no output to stdout, as mentioned in the comments by glenn jackman.
Use -F [field separator] to split the lines on “s: awk -F ‘”‘ ‘{print $2}’ your_input_file or for input from pipe <some_command> | awk -F ‘”‘ ‘{print $2}’ output: A B C D
Have you tried: echo “12|23|11″ | awk ‘{split($0,a,”|”); print a[3],a[2],a[1]}’
sed -n ‘/^START=A$/,/^END$/p’ data The -n option means don’t print by default; then the script says ‘do print between the line containing START=A and the next END. You can also do it with awk: A pattern may consist of two patterns separated by a comma; in this case, the action is performed for all lines … Read more
Try grep -Fwf file2 file1 > out The -F option specifies plain string matching, so should be faster without having to engage the regex engine.
In awk, Since 1 always evaluates to true, it performs default operation {print $0}, hence prints the current line stored in $0 So, awk ‘$2==”no”{$3=”N/A”}1’ file is equivalent to and shorthand of awk ‘$2==”no”{$3=”N/A”} {print $0}’ file Again $0 is default argument to print, so you could also write awk ‘$2==”no”{$3=”N/A”} {print}’ file In-fact you … Read more