|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sed append without using new line
im trying to append to the end of the line using sed but I want to do it without creating a new line the text to which I want to append is all in capital letters. I want to do something like this: Code:
LINE]Foo but when I do this: Code:
/[A-Z]/a\ ] Foo it prints foo on a new line: Code:
LINE ]Foo how can I get sed to append text without the new line? |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Try something like this: I will add Eon at the end of the line Code:
$ cat data Knight Eon Hello World Hello Earth How is everyone $ sed -e '$s/\(.*\)/\1Eon/g' data Knight Eon Hello World Hello Earth How is everyone Eon |
| The Following User Says Thank You to knight_eon For This Useful Post: | ||
mrjavoman (02-07-2012) | ||
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Code:
echo "LINE" | sed 's/$/]FOO/' This appends the "]FOO" to end of the line. Thanks, Kalai Last edited by Franklin52; 02-07-2012 at 02:56 AM.. Reason: Please use code tags for code and data samples, thank you |
| The Following User Says Thank You to kalpeer For This Useful Post: | ||
mrjavoman (02-07-2012) | ||
|
#4
|
|||
|
|||
|
thanks for the replays but what I really want to do is append to only the lines that are in all capital letters. sort of like if i Have: Code:
TITLE this is a line this is a line then i what it to be Code:
TITLE]Foo this is a line this is a line Thank you |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
try this Code:
touch /tmp/test.$$ while read line do check=`echo $line | tr -dc [A-Z]` if [ ! -z "$check" ];then echo "$line" | sed 's/$/]Foo/' >> /tmp/test.$$ else echo "$line" >> /tmp/test.$$ fi done < one cat /tmp/test.$$ one: TITLE this is a line this is a line Output: TITLE]Foo this is a line this is a line Last edited by Franklin52; 02-07-2012 at 02:58 AM.. Reason: Code tags |
| The Following User Says Thank You to kalpeer For This Useful Post: | ||
mrjavoman (02-07-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
It can be written in sed one liner. Here is how: Code:
$ cat data Knight Eon Hello WORLD Hello Earth LINE How is everyone $ sed -e 's/\(\L.*\)/\1]Foo/g' data Knight Eon Hello WORLD]Foo Hello Earth LINE]Foo How is everyone Hope this will help you
|
| The Following User Says Thank You to knight_eon For This Useful Post: | ||
mrjavoman (02-07-2012) | ||
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Code:
sed 's/^[A-Z][A-Z]*$/&\]FOO/' infile or with whitespace tolerance: Code:
sed 's/^[ \t]*[A-Z][A-Z]*[ \t]*$/&\]FOO/' infile |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
mrjavoman (02-07-2012) | ||
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find a certain line and append text to the end of the line | peachclift | Shell Programming and Scripting | 2 | 12-19-2011 03:10 PM |
| Append next line to previous line when one pattern not found | kannansr621 | Shell Programming and Scripting | 4 | 09-12-2011 03:31 PM |
| Append each line to next previous line in a file | sudhakaryadav | Shell Programming and Scripting | 8 | 06-01-2009 11:21 AM |
| Append line that does not contain pipe to it previous line | ainuddin | Shell Programming and Scripting | 11 | 11-11-2008 09:58 AM |
| Joining lines in reverse. append line 1 to line 2. | dwalley | Shell Programming and Scripting | 7 | 08-04-2008 07:11 AM |
|
|