appending strings in the files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers appending strings in the files
# 1  
Old 03-09-2007
appending strings in the files

I have some files created by a process in UNIX. I wanted to do some file processing:

1. I want to append a string "EOF" as the first word on the last line of all the files except the last file.

2.Similarly, I want to append "BOF" string as the first word to all the files except the first file, also this "BOF" string should be repeated for lines, till it find a line <abcd>.

Thanks for ur time!
# 2  
Old 03-09-2007
Try this...But this may not be the quickest way to do this..

for i in $(ls * |sed -n '1!p'| sed -n '$!p')
do
[[ -f "$i" ]] && { echo "BOF$(cat $i)" > $i; echo "$(cat $i)EOF" >$i; }
done

echo "BOF$(ls *|sed -n '1p;')" >$(ls *|sed -n '1p;')
echo "$(ls *|sed -n '$p;')EOF" >$(ls *|sed -n '$p;')
# 3  
Old 03-09-2007
Try this...But this may not be the quickest way to do this..Also,I assume that all the files in the current directory requires this update


for i in $(ls * |sed -n '1!p'| sed -n '$!p')
do
[[ -f "$i" ]] && { echo "BOF$(cat $i)" > $i; echo "$(cat $i)EOF" >$i; }
done

echo "BOF$(ls *|sed -n '1p;')" >$(ls *|sed -n '1p;')
echo "$(ls *|sed -n '$p;')EOF" >$(ls *|sed -n '$p;')
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. UNIX for Dummies Questions & Answers

Appending two text files

Hi, i am using unix server and bash shell.. i have two csv files... i have file 1 as below... arun bvb ssx ccc and file 2 as below manas friu dfgg cat (3 Replies)
Discussion started by: arunmanas
3 Replies

3. Shell Programming and Scripting

appending two strings

Hi, I have a small doubt. Here is the code snippet for which the output that I'm getting are a bit surprising. testing.sh #!/bin/sh arg_1=$1 echo "arg passed by user is:${arg_1}" mapping=`grep ${arg_1}= testing.conf | awk -F"=" '{print $2}'` echo "mapping is $mapping"... (4 Replies)
Discussion started by: badrimohanty
4 Replies

4. Shell Programming and Scripting

Appending two files vertically

Hi Need ur help for the below question. I have two files File-1 & File-2. File-1(This is a fixed file i.e. the content of this file is not going to change over a period of time) ------ a b c d e File-2 (This is a file which changes daily but the record count remains the same)... (1 Reply)
Discussion started by: 46019
1 Replies

5. Shell Programming and Scripting

Need assistance with appending strings using sed and variables

HI, Can't seem to find anything on the forums to fix this. I have a file, one line within this will not have a specific string at the end. I have the string, but need to append it to the specific line which has it missing. I need to use a variable for this, $string - I am using double... (13 Replies)
Discussion started by: mandriver
13 Replies

6. Shell Programming and Scripting

appending strings

Hi , while trying to append two strings, it is not properly coming. my code will be like this str1=_TrackingEAR srt2=1.0.0-20080523.155438-12 i am trying to build str3=$str1$str2.tgz but it is appending the last value ot the begingin of the string , but i expect to the end of the... (1 Reply)
Discussion started by: scorpio
1 Replies

7. Shell Programming and Scripting

appending strings to variable

is it possible? as i keep reading a file, i want one particular variable to keep storing the line that i've read so far (1 Reply)
Discussion started by: finalight
1 Replies

8. UNIX for Dummies Questions & Answers

Appending the two files

hi, I want to append to two files into a third file without new line like this: file 1: I am learning the unix file 2: Unix is very intersting When I am trying cat file1 file2 >> file3 I am getting: I am learning the unix Unix is very interesting But I want that to be in... (3 Replies)
Discussion started by: harish409
3 Replies

9. UNIX for Dummies Questions & Answers

appending files

I have 25 transaction files that need to be put into one file and have the date of the file appended at the end of the line, anyone got a one liner or simple script to help me out thanks - Ed (4 Replies)
Discussion started by: edog
4 Replies
Login or Register to Ask a Question