SED Question -- on appending to a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers SED Question -- on appending to a file
# 1  
Old 08-29-2005
Question SED Question -- on appending to a file

Smilie
I have a script that Cats a flat database file which contains 12 columns into sed. I want to add a 13th column which includes " ,2005-08-29 " * The date needs to be the current date.

This 13th column would be appended to the end of each line.

Does anyone have a clue how to do this using SED?

Smilie
# 2  
Old 08-29-2005
I dont think you need to use a cat or sed for that.

It can be as simple as this.

Code:
while read line
do
echo "$line ,$(date +%Y-%m-%d)" >> flatfile.new
done < flatfile

flatfile is your flat database file.

Vino
# 3  
Old 08-29-2005
If you need to use sed, use this

Code:
sed -e "s#\(.*\)#\1 ,$(date +%Y-%m-%d)#g" flatfile > flatfile.new

vino
# 4  
Old 08-29-2005
Here is my current command which works:

[root@localhost ds1f]# cat /mnt/winbox/list_measurement/ds1c/ds1_f.rome_27A03A 2>> error_log | sed '1,3d;s/^/27A03A,/;s/$ > /mnt/winbox/ds1_f.rome_27A03A

I tested the above sed command and here is its response

Ran this ---->
[root@localhost ds1f]# cat /mnt/winbox/list_measurement/ds1c/ds1_f.rome_27A03A 2>> error_log | sed '1,3d;s/^/27A03A,/ | sed -e "s#\(.*\)#\1 ,$(date +%Y-%m-%d)#g" > /SBS/list_measurement/ds1c/ds1_f.rome_27A03A

Reply was this ------>
sed: -e expression #1, char 19: unknown option to `s'
# 5  
Old 08-29-2005
Code:
FILE="list_measurement/ds1c/ds1_f.rome_27A03A"

[root@localhost ds1f]# cat "/mnt/winbox/$FILE" 2>> error_log | 
sed -e '1,3d;s/^/27A03A,/' -e "s#\(.*\)#\1 ,$(date +%Y-%m-%d)#g" > "/SBS/$FILE"

vino
# 6  
Old 08-29-2005
Thanks

Vino...Thank you sooo much for your help...

Here is the command i have that works:

[root@localhost ds1c]# cat /mnt/winbox/list_measurement/ds1c/ds1_f.rome_27A03A 2>> error_log | sed -e '1,3d;s/^/27A03A,/' -e "s#\(.*\)#\1 ,$(date +%Y-%m-%d)#g" > /SBS/ds1_f.rome_27A03A

Here is the Results

,2005-08-29dale,3:02 am MON AUG 29, 2005,6:25 pm SAT JUN 25, 2005,08/28,03:09,0,0,0,0,N/A,N/A

Here is what i am looking for:

27A03A,orestdale,2:17 pm FRI AUG 26, 2005,6:25 pm SAT JUN 25, 2005,08/26,05:39,0,0,0,0,N/A,N/A,2005-08-29

all i need to do is put 27A03A, at the beginning of each line and ,2005-08-29
Smilie

Last edited by Redg; 08-29-2005 at 03:58 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed command help (appending)

I need to append a user to the end of a group in the /etc/group file ftp::49:user1,user2... what I want to to add a new user to the group file so that I won't have to open it up and append manually and I can't user "usermod" it fails this user will be coming from a variable (11 Replies)
Discussion started by: slufoot80
11 Replies

2. Shell Programming and Scripting

sed appending problem

i have a number of java files containing eg: --------------myfile.java-------------- package zip.fun.myfiles; import java.* import something..; import sdfdfdsa; ... ... -------------------------------------------- Now I need to append / insert a line as follows: ... (10 Replies)
Discussion started by: linuxadmin
10 Replies

3. UNIX for Dummies Questions & Answers

sed - appending text

Hey all I am trying to append a file called datebook.txt. I want to append the end of each line containing the name Fred with three ***. I believe I need to make the * loose its meta character meaning in addition to using the append command. I have tried several variations of this command and I... (3 Replies)
Discussion started by: citizencro
3 Replies

4. Shell Programming and Scripting

Awk/Sed - appending within file

hello all, First time post here. I have searched a bit but could not find an exact answer. I have about a week's experience of Sed and Awk, and am having fun, but am a little stuck. I am reformatting an xml file into json format. I have got this far: {"clients": ...and so on. What I want... (22 Replies)
Discussion started by: singerfc
22 Replies

5. Shell Programming and Scripting

sed appending needed only after first instance

Hi, Here is my piece of code used with sed in shell script: sed -i '/<falsemodule-option>/ a\<LdapLogin>' myxmlfile The problem that i am facing with the above is that in 'myxml' file i have mulitple instances of <falsemodule-option> so when i execute the above sed command, it is appending... (10 Replies)
Discussion started by: sunrexstar
10 Replies

6. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

7. Shell Programming and Scripting

appending a file using sed in ksh

i am trying to append a 5 line SGML file(file1) with a 500,000 line SGML file (file2). file1 is a template, so i wish to preserve. i only want to add lines 5 to the end of file2. i have: cp file1 temp1 sed -n '5,$p' file2 >> temp1 when i check the tail of temp1, i consistantly find the... (3 Replies)
Discussion started by: smac
3 Replies

8. Shell Programming and Scripting

appending and sed

Hello, I want to add string #REAL at the end of all lines that contain real numbers. How to do this using sed ? (1 Reply)
Discussion started by: scotty_123
1 Replies

9. Shell Programming and Scripting

appending to sed output of one file into the middle of file

hi, i have a file file1 file2 ----------- ----------------- aa bbb ccc 111 1111 1111 ddd eee fff 222 3333 4444 ggg hhh... (5 Replies)
Discussion started by: go4desperado
5 Replies

10. Shell Programming and Scripting

Appending string to xml file using "sed"

Hi folks, Following a section in opmn.xml file: </process-type> <process-type id="OC4J_RiGHTv_IRD1" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question