sed to search and insert column
I have the following file.
B0 49.2230869 -102.5743868 C 1LPRK 654.90 C 1PREU 3693.90 C 1JRSU 3693.90 C 1UVNG 3693.90 C 1LVGD 3924.90 C 1USHV 4064.00 C 1LRSV 4120.10 C 1GVBG 4180.10 C 1LGVB 4270.00 C 1WTRS 4310.00 C 1SPRF 4482.90 C 1MLKR 1912.10 C 1PLZU 4728.00 C 1MSSU 4728.00 C 1PPLR 4728.00 C 1RCLF 4768.00 C 1ONGR 4821.90 C 1MIDL 4857.90 C 1CLRD 2519.00 C 1SSPK 2756.00 C 1LCLD 2853.00 C 1BFS 2995.10 C 1VKNG 3097.00 C 1JLFU 3157.20 C 1MNVL 3346.10 I need to insert text ABCDEF starting at position 26 if a line starts with C. I need it to look like: C 1VKNG ABCDEF 3097.00 C 1JLFU ABCDEF 3157.20 C 1MNVL ABCDEF 3346.10 Any help would be appreciated. I would prefer to use sed to do this and not perl. Thanks in advance |
position 26? I don't understand with your example.
|
The file above does not look right. It lost the formatting when i saved the post.
I want to search a file for a line that starts with C. on this line I want to insert ABCDEF into column 26 - 31. All the other text on the line needs to remain untouched. C 1VKNG ABCDEF 3097.00 |
i cant get the line to show the spaces. ABCDEF should be 26 spaces from the left.
|
Quote:
use code-tags to preserve the correct formatting. [CODE]post data here[/CODE] |
Hi,
Quote:
[code] your stuff goes here [/code] |
Code:
sed -r '/^C/s/^(.{25})/\1ABCDEF/' file |
Not sure about sed, but did you mean something like:
Code:
$awk '/^C/{$NF = sprintf("%31s %s","ABCDEF",$NF)}1' file |
Try this:
Code:
$ grep "^C" input | sed 's/.\{25\}$/ABCDEF &/' |
Hi,
Code:
sed -r '/^C/s/^(.{25,30})/\1ABCDEF/' infile |
Might need OP to do the code tag thing as I am a bit confused on whether the data already has multiple spaces that are to be replaced or if the original file is as shown but
only the new data should contain spaces (as per my solution)?? |
Quote:
Code:
sed -r '/^C/s/^(.{25}).{6}/\1ABCDEF/' file |
Quote:
sed -r '/^C/s/^(.{25})/\1ABCDEF/' infile This works great. thanks for the help everyone. |
Quote:
|
Quote:
Quote:
If it is what you wanted: You're welcome :) |
All times are GMT -5. The time now is 05:30 PM. |