Very Basic: replace value flanked by tabs
I should know how to do this, but I'm very new to unix.
I have a table of data, which is tab delimited. I need something, preferably sed, that will delete the 2nd value here, while preserving the placeholder: 3 1 1.0 0.10 0.1 1.0e-1 1.0010 to this 3 1.0 0.10 0.1 1.0e-1 1.0010 Thanks for helping a newb- |
Give this a try:
Code:
sed -i 's/^\([[:digit:]]\{1,\}\t\)[[:digit:]]\{1,\}\t\(.*\)/\1\2/' /path/to/my/file |
Quote:
|
Code:
sed 's/\t[^\t]*\t/\t \t/1' filename > newfilename Why not AWK? Simply print the fields you want, and print your placeholder (I used a space) for the ones you don't want. PS: Have you read the material suggested in your earlier thread? |
Edited my post above due to a typo, sorry.. didn't test it
And again! geez... you should always test ! Here's a working one: Code:
sed 's/^\([[:digit:]]\{1,\}[[:blank:]]\)[[:digit:]]\{1,\}[[:blank:]]\(.*\)/\1\2/' ./myfile Code:
sed 's/^\([[:digit:]]\{1,\}[[:blank:]]\)[[:digit:]]\{1,\}[[:blank:]]\(.*\)/\1\2/' ./test |
For some reason was unable to get either of the above suggestions to work.
However, this works except on values at the beginning or end of the line: sed -r 's/(\t)1(\t)/\1\2/g' I tried this to replace the ones the beginning, but it didn't work: sed -r 's/(\t|^)1(\t)/\1\2/g' Does anyone have a solution to this problem?? The reason why I'd prefer sed is because I know the syntax a little, whereas with awk, I don't know it at all. But if there's an easy awk solution, then by all means please share. :) |
Ended up using this:
sed -r 's/(\t)1(\t)/\1\2/g' | sed -r 's/^1(\t)/\1/g' | sed -r 's/(\t)1$/\1/g' |
Note: I've actually inserted TABs where you had spaces.
Code:
$ cat tabs Cheers, Tink |
Quote:
|
All times are GMT -5. The time now is 06:15 PM. |