Visit Our UNIX and Linux User Community


Using SED to append character to each line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using SED to append character to each line
# 1  
Old 07-08-2006
Using SED to append character to each line

Hey - my first post here, and I'm a total SED newb. I've looked around for previous help on this, but have so far been unsuccessful.

I have a program (AMStracker for OS X) that outputs data in the terminal. Output is in this form:

.
.
.
3 0 -75
3 0 -76
3 0 -77
5 0 -75
3 0 -76
3 0 -75
5 0 -76
6 0 -76
2 0 -75
2 0 -75
5 0 -76
3 0 -76
5 0 -77
3 0 -75
3 0 -77
.
.
.

column ranges are from -255 to +255, but that should not matter here...

All I want to do is pipe AMStracker output into SED so that the final output looks like this:

.
.
.
3 0 -75;
3 0 -76;
3 0 -77;
5 0 -75;
3 0 -76;
3 0 -75;
5 0 -76;
.
.
.

Basically I want to append a ';' to each line.

I've been fooling around and so far have this:

./amstracker -u 0.05 -s | sed a\\n";"

Which does not work. I get errors I don't undestand:

--> sed: 1: "a\n;": extra characters after \ at the end of a command

Can anyone offer some help? I woudl assume that something liek this should be rather simple for SED. Should I be using another tool?
# 2  
Old 07-08-2006
I found the answer on this forum... sorry for the repeat.

Here is the link to the post that helps:

https://www.unix.com/unix-for-dummies-questions-and-answers/21191-using-sed-append-text-end-each-line.html
# 3  
Old 07-08-2006
Quote:
Originally Posted by c0nn0r
I found the answer on this forum... sorry for the repeat.

Here is the link to the post that helps:

https://www.unix.com/unix-for-dummies-questions-and-answers/21191-using-sed-append-text-end-each-line.html
Actually this implementation does not work for me. Not entirely at least.

I do get the output I am looking for with this, ie.:

.
.
.
10 0 8;
10 0 8;
10 0 8;
10 0 7;
10 0 8;
.
.
.

However, it strips either the carriage return or the new line, or both, which I need to retain. For example:

running

/amstracker -u 0.05 -s | sed 's/$/;/'

gives the output seen above, but if I try running

/amstracker -u 0.05 -s | sed 's/$/;/' | sed 's/$/;/'

Which I should be able to do (it would just add another ';' to each line right?)

In reality I see nothing in the terminal when I run this.

I'm trying to add a newline or carriage return after the ;, but I'm not sure how...

Again, I'm a SED newb.
# 4  
Old 07-08-2006
Code:
/amstracker -u 0.05 -s | sed 's/.*/&;/'

# 5  
Old 07-08-2006
Quote:
Originally Posted by reborg
Code:
/amstracker -u 0.05 -s | sed 's/.*/&;/'

Thanx, but it still does not work for me.

I'll be more specific:

After the ./amstracker -u 0.05 -s | sed 's/.*/&;/'

I want to pipe it into netcat (nc) so I can send it over the network, or to another port on the same machine. I know it's a weird setup, but it's a hack that will save me a lot of work in the future.

When I do:

./amstracker -u 0.05 -s | sed 's/.*/&;/' | nc 127.0.0.1 5001

it connects to an instance of: nc -l -p 5001 (on 127.0.0.1)

but no data goes thorough...

I'm cleary an idiot.


Any more suggestions?

Previous Thread | Next Thread
Test Your Knowledge in Computers #837
Difficulty: Medium
SOAP was designed as an object-addressing protocol in 1998,
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Append each line based upon the character size

I have a huge file which contains multiple lines. It need to check whether character length is not more than 255 each line. If its not then it should remove the character up to column. I have described in the output below. If its more than that the next line should start with call but if the... (1 Reply)
Discussion started by: JoshvaPeter
1 Replies

2. Shell Programming and Scripting

sed - append line after block

Hi, I posted in another section, but no reply yet. I have an ini file with sections denoted as follows (for example) blah=blah blee=blee bloo=bloo blur=blur blaa=blaa I have ksh script that needs to append a line ${line} to the end of section ${section} I saw this... (7 Replies)
Discussion started by: andyatit
7 Replies

3. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

4. Shell Programming and Scripting

Search for a string, then append character to end of that line only

I have 2 files that I am working with $ cat file1 server1 server3 server5 server6 server8 $ cat file2 server1;Solaris; server2; SLES; server3;Linux; server4; Solaris; server5;SLES; server6;SLES; server7;Solaris; server8;Linux; (1 Reply)
Discussion started by: snoman1
1 Replies

5. Shell Programming and Scripting

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: LINE]Foo but when I do this: //a\ ] Foo it prints foo on a new line: LINE ]Foo ... (11 Replies)
Discussion started by: mrjavoman
11 Replies

6. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

7. Shell Programming and Scripting

How to append line with sed?

Input: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly Output should be: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly How can it be done with sed? (5 Replies)
Discussion started by: cola
5 Replies

8. Shell Programming and Scripting

How to append a character to the last but one field on a specific line?

Hi Guys, I have a file like this: aaa b c d e f fsss g h i k l qqq r t h n I want: aaa b c d e f fsss g h i k l qqq r t h , n ggg p t e d u qqq i o s , k (2 Replies)
Discussion started by: npatwardhan
2 Replies

9. Shell Programming and Scripting

Sed append newline character

Hi All, I am new to Shell scripting.. I have a task to parse the text file into csv format. more then half the things has done. But the problem is when I use the sed command in shell script. it appends newline character at the end of the line. and so when I open the file in CSV it's format... (3 Replies)
Discussion started by: Gaurang033
3 Replies

10. Shell Programming and Scripting

append a character at end of each line of a file

Hi, i want to append a character '|' at end of each line of a file abc.txt. for example if the file abc.txt conatins: a|b|c 1|2|33 w|2|11 i want result file xyz.txt a|b|c| 1|2|33| w|2|11| I know this is simple but sumhow i am not able to reach end of line. its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies

Featured Tech Videos