appending strings in the files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers appending strings in the files
# 1  
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  
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  
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;')
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #775
Difficulty: Medium
UML state machine is a significantly enhanced realization of the mathematical concept of a finite automaton in computer science applications.
True or False?

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 multiple files

I am trying to append multiple files in a directory cat /a/file1.txt /a/file2.txt /a/file3.txt /a/file4.txt > /a/file.txt Except file2 every other file is appending. I interchanged file names and ran the command. Whatever file repeating in the second position is missing in output... (6 Replies)
Discussion started by: eskay
6 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 all files that are in a directory

Hi, This might be a question that has an easy solution but im new to unix. I have a project where I have to append files that are in a directory and then read those files out. can anyone help me this this problem??? thanks in advance, TDS (1 Reply)
Discussion started by: TDS
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

Featured Tech Videos