I have a file with many lines in each line there are many columns(fields) separated by blank \" \" the numbers of columns in each line are different I want to remove the fir
You can do it with cut:
cut -d " " -f 3- input_filename > output_filename
Explanation:
cut: invoke the cut command-d " ": use a single space as the delimiter (cut uses TAB by default)-f: specify fields to keep3-: all the fields starting with field 3input_filename: use this file as the input> output_filename: write the output to this file.Alternatively, you can do it with awk:
awk '{$1=""; $2=""; sub(" ", " "); print}' input_filename > output_filename
Explanation:
awk: invoke the awk command$1=""; $2="";: set field 1 and 2 to the empty stringsub(...);: clean up the output fields because fields 1 & 2 will still be delimited by " "print: print the modified lineinput_filename > output_filename: same as above.This might work for you (GNU sed):
sed -r 's/^([^ ]+ ){2}//' file
or for columns separated by one or more white spaces:
sed -r 's/^(\S+\s+){2}//' file
Its pretty straight forward to do it with only shell
while read A B C; do
echo "$C"
done < oldfile >newfile
Using awk, and based in some of the options below, using a for loop makes a bit more flexible; sometimes I may want to delete the first 9 columns ( if I do an "ls -lrt" for example), so I change the 2 for a 9 and that's it:
awk '{ for(i=0;i++<2;){$i=""}; print $0 }' your_file.txt