Append pipe | at the end of all the rows except header n trailer for all the files under a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Append pipe | at the end of all the rows except header n trailer for all the files under a directory
# 1  
Old 09-26-2019
Append pipe | at the end of all the rows except header n trailer for all the files under a directory

Hi Experts

Need help...
I am looking for a Unix script to append pipe | at the end of all the rows (except header and trailer)in all the files placed under the directory /interfaces/Temp

e.g.
Code:
Header
row1
row2
row3
Trailer

The script should read all the files under /interfaces/Temp and append | at the end of rows (except header and trailer).
Post execution of Script, all files under the folder should look like this:
Code:
Header
row1|
row2|
row3|
Trailer

Thanks
Phani
Moderator's Comments:
Mod Comment
Use code tags please.

Last edited by Peasant; 09-27-2019 at 12:55 AM.. Reason: Added code tags
# 2  
Old 09-26-2019
Any attempts / ideas / thoughts from your side?
# 3  
Old 09-26-2019
I tried below command. But it works for only one file. I am trying to read all the files under a specified folder.

Code:
sed 's/$/|/' file.txt > new-file.txt

# 4  
Old 09-27-2019
Try with a shell loop:
Code:
for FN in *; do sed -n '1 {p;b;}; ${p;b;}; s/$/|/p;' $FN > new_$FN; done

EDIT: or,
Code:
for FN in *; do sed  '1bL; $bL; s/$/|/; :L' $FN; done


Last edited by RudiC; 09-27-2019 at 12:21 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Header and trailer Check in UNIX

I am planning to automate multiple files through Unix script. Could you please guide for making the automation for multiple files ? Eg. I have to check header and footer for all files in the particular path and the header pattern should match with the filename. Filename- Filename.txt... (2 Replies)
Discussion started by: karthick2020333
2 Replies

2. Shell Programming and Scripting

Sort without Header and Trailer

Hi , My UNIX system is SUN Solaris. I am trying to do a simple thing as described below. I have a PIPE delimited file that has header and trailer. So the file is something like below: Test1.txt looks like something below: field_data1|field_data2|and some more data --Header ... (5 Replies)
Discussion started by: Saanvi1
5 Replies

3. Shell Programming and Scripting

Verify the header and trailer in file

please see my requirement, I hope I am clear. (9 Replies)
Discussion started by: mirwasim
9 Replies

4. UNIX for Dummies Questions & Answers

Adding header and trailer into a file

Hi, I want to add the below Header to all the files in sequence File1,File2,File3...etc "ABC,<number of chracter in the file>" e,g - If File1 is as below pqrstuvdt abcdefgh then I want to add the above header into it ,So that File1 becomes as below ABC,17 pqrstuvdt abcdefgh ... (9 Replies)
Discussion started by: spari2
9 Replies

5. Shell Programming and Scripting

Header as is.. trailer count

i have .DAT file FILE1.DAT 1200910270040625 2123456789 J123456 ABC 2123456789 K123456 ABC 2222222222 L123456 DEF 2333333333 M12345 GHI 30000004 My outfile FILE2.TXT should have like this, I need the header value as ie (1200910270040625 ) body rows remove the duplicate rows and the... (2 Replies)
Discussion started by: kshuser
2 Replies

6. Shell Programming and Scripting

search directory-find files-append at end of line

Hi, I have a command "get_data" with some parameters in few *.text files of a directory. I want to first find those files that contain this command and then append the following parameter to the end of the command. example of an entry in the file :- get_data -x -m50 /etc/web/getid this... (1 Reply)
Discussion started by: PrasannaKS
1 Replies

7. Shell Programming and Scripting

Merge text files while combining the multiple header/trailer records into one each.

Situation: Our system currently executes a job (COBOL Program) that generates an interface file to be sent to one of our vendors. Because this system processes information for over 100,000 employees/retirees (and growing), we'd like to multi-thread the job into processing-groups in order to... (4 Replies)
Discussion started by: oordonez
4 Replies

8. Shell Programming and Scripting

Append Spaces At end of each line Leaving Header and Footer

How to append constant No of spaces suppose 52 at end of each line in a file (xyz) excluding first and last line. Please Help me out for the same. (1 Reply)
Discussion started by: deepam
1 Replies

9. UNIX for Dummies Questions & Answers

Append Header and Trailer

Hi everyone, I am new to Unix programming. My inquries is:- a) How to add a Header and Trailer in the set of data b) Include a number count of the data in the trailer The set of data only contained the information of 'Customer's Name' and 'Account Number'. I would like to add the Header... (2 Replies)
Discussion started by: balzzz
2 Replies

10. UNIX for Dummies Questions & Answers

Copy all the files with time stamp and remove header,trailer from file

All, I am new to unix and i have the following requirement. I have file(s) landing into input directory with timestamp, first i want to copy all these files into seperate directory then i want to rename these files without timestamp and also remove header,trailer from that file.. Could... (35 Replies)
Discussion started by: ksrams
35 Replies
Login or Register to Ask a Question