Hello,
A basic query. How can I remove a string from a specific column.
For example, remove "abcd" just from column 2 in example file:
abcd abcd1
abcd abcd2
abcd abcd3
to get output:
abcd 1
abcd 2
abcd 3
Thank you!
Hello,
A basic query. How can I remove a string from a specific column.
For example, remove "abcd" just from column 2 in example file:
abcd abcd1
abcd abcd2
abcd abcd3
to get output:
abcd 1
abcd 2
abcd 3
Thank you!
One way:
awk '{ gsub(/abcd/,"", $2); print } ' filename > newfilename
Using Perl one-liner:
perl -pe 's/^([a-z]+).*([0-9]+)/$1 $2/g' file
abcd 1
abcd 2
abcd 3
Too make change to file permanent, add the -i + extension switch to make a backup of the file, then make change to original file.
perl -i.bak -pe 's/^([a-z]+).*([0-9]+)/$1 $2/g' file
Should end up with "file" and "file.bak" which is a backup of the original file. Original "file" now contains:
abcd 1
abcd 2
abcd 3
Thanks everyone!
cut -c1-5,10- filename
I did this with the following file:
abcd abcd1
abcd abcd14
abcd abcd127
and got
abcd 1
abcd 14
abcd 127