Need shell script for inserting New line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need shell script for inserting New line
# 8  
Old 04-20-2010
Code:
sed -n '1d; $!{x;s/\(.\)/\1\
/p512 ;}' file

# 9  
Old 04-21-2010
Hi Danmero and soleil,

Thanks for you response. I am getting this. But i need header record and trailer record in the samefile. my detail records are splitting but my header and trailer records are not showing.
I need my file as

header
summary1
detail1
summary2
detail2
summary3
detail3
trailer1
trailer2

Can you please let me know how to get my header and trailer record
# 10  
Old 04-21-2010
Code:
host1> head -1 file1 > outfile
host1> sed '1d;$d' file1|sed '$d'|awk '{print substr($0, 1, 8); print substr($0, 9, 7)}' >> outfile
host1> tail -2 file1 >> outfile
host1> cat outfile
header
summary1
detail1
summary2
detail2
summary3
detail3
trailer1
trailer2

# 11  
Old 04-21-2010
Hi soleil
sorry for asking many questions.
I am getting this message
awk: record `RW587241376ELVIA ...' too long

actually my file is like xxxx.mf file. This contain one big record with 32MB. If I open through textpad, entire file shows in 1 line as
headersummary1detail1summary2detail2summary3detail3trailer1trailer2.

If i open with notepad, file shows like
header
summary1detail1
summary2detail2
summary3detail3
trailer1
trailer2

when I open in unix box, it says too long. so user needs to cut the detailrecords.
Can you please suggest me.
Sorry for asking many questions. I am new to shell scripts.
Plz help me.
# 12  
Old 04-21-2010
Try using 'gawk' instead of 'awk' if you have it available on your system and see if that fixes the problem or not. I think 'awk' has some limitation with record lengths.
# 13  
Old 04-21-2010
It saying
ksh: gawk: not found

I think there is no gawk command in my system.
I dont know why my file is showing 1 line when I open with textpad. shows multiple lines when I open with notepad. It says line too long when I open in UNIX.
Can you please suggest me how to resolve this issue.
# 14  
Old 04-21-2010
To keep the first line and the last two lines unchanged, while splitting any other lines at the 512th byte:

Code:
sed '1n; 2{h;d;}; ${H;g;q;}; $!{x;s/\(.\)/\1\
/512 ;}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting shell script input data automatically from a text file

Dear experts, I am new to linux programming. I have a shell script which i should run it on all my samples. I only define input and out put for this script. The inputs are 3 numbers(coordination numbers) which are available in a series of text file. Since i have a lots of samples, it takes a... (5 Replies)
Discussion started by: mohamadreza
5 Replies

2. UNIX for Dummies Questions & Answers

Inserting new line

Hi all, I want ot print a header with new line in the end. I am using echo like echo "this is header" I want output like This is header $ I tried -e also but it's not working. echo - e Can anyone help please? (6 Replies)
Discussion started by: dsa
6 Replies

3. Shell Programming and Scripting

Need help on inserting data from text file to excel using shell script

Hi, Please help me on this. I want to insert data from text file to excel using shell script nawk -v r=4 -v c=4 -v val=$a -F, 'BEGIN{OFS=","}; NR != r; NR == r {$c = val; print}' "file.csv" I used above one to insert $a value in 4th row, 4th column in an excel file.csv and it... (3 Replies)
Discussion started by: suman.frnz
3 Replies

4. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

5. Shell Programming and Scripting

script for inserting line at specific place in file

I use zentyal for my server admin, which is great but zentyal auto-generates config file on boot and hence overwrites any changes made directly to config files. In order to allow multiple user access to a MS ACCESS database, I need to customise the smb.conf file and add the following line to the... (9 Replies)
Discussion started by: barrydocks
9 Replies

6. Shell Programming and Scripting

Help with inserting a line

Hello, I am new to this forum. I have a question in Unix shell scripting. Here is my requirement I have 1000 files and I need to insert a header with one line at the top of each of the 1000 files. Please let me know if you have any solution for this Thanks in advance. Raj (4 Replies)
Discussion started by: trajashekar
4 Replies

7. Shell Programming and Scripting

Inserting a line in a file after every alternate line

Friends , I have a large file and i need to insert a line after every line.I am actually unaware how to do it.Any help appreciated. My File control station *ATM* , qread $OSS.Jul13A.FI01 interval 1 intcount 1 control station *ATM* , qread $OSS.Jul13A.FI02 interval 1 intcount... (4 Replies)
Discussion started by: appu2176
4 Replies

8. UNIX for Advanced & Expert Users

Inserting a line before the line which matches the patter

Hi Is there any command where we can insert a line "2|||" before every line starting with "3|" my input is as follows 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 2|EN_GB||Electrogalvanize 0.5 m2 ( Renault ) 1|ETG|12345 3|88.51|||GBP|| desired output... (10 Replies)
Discussion started by: laxmi131
10 Replies

9. Shell Programming and Scripting

Inserting a new line

I have a file where each line starts with a "update" statement. I want to insert a new line, after each line, with the words "go" in the new line. Can someone help me out with this? (1 Reply)
Discussion started by: ssmallya
1 Replies

10. UNIX for Dummies Questions & Answers

inserting line??

guys can anyone tel me how to insert a line in a file(bash) using line number i wanna insert the line using LINE NUMBER...i know for inserting above or below a perticular line we can use sed a\ or i\.... thanks in advance.... (7 Replies)
Discussion started by: anj
7 Replies
Login or Register to Ask a Question