sed on a one line file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed on a one line file
# 8  
Old 06-24-2011
I used the
fold -w 592 bigfile1  > bigfile2

given by itkamaraj up there and it works very well.

I just tried with the -c option and it seems it works as well
# 9  
Old 06-24-2011
Originally Posted by itkamaraj
use fold command


In your case, it is

fold -w 592 myfile.tgt  > /tmp/newfile.tgt

Originally Posted by marcello_fr
@itkamaraj : the command fold is exactly what i need, thank you very much ! it works very well Smilie
Be aware that the fold command will treat any tabs and backspace characters in your file specially. If those characters may occur in your data and you require splitting strictly after 592 bytes, you need to use the -b option.

If you are dealing with multibyte characters, want to specify width in characters instead of bytes, but want to avoid fold's special interpretation of tab/backspace, then you should use a different tool.

For more information on the special behavior, see the DESCRIPTION and RATIONALE sections @ fold

Perhaps none of this is of any relevance to your situation. I merely mention it in case it is.

This User Gave Thanks to alister For This Post:
# 10  
Old 06-24-2011
you can try this and check the result file "myfile.tgt"
i=1;>myfile.tgt;while [ $i -le $(sed -n '$=' myfile.src ) ]; do sed -ne ''$i' s/\(.\{592\}\)/\1\
> /gp' myfile.src>>myfile.tgt;((i++)); done

# 11  
Old 06-24-2011
Thank you Alister for thoses precisions. I was not aware of those little important subtleties.
My file is hopefully a good old text file, with monobyte characters, no backspace, no tabulation, and no special character. There are only letters, figures and spaces here.
So i think "fold" will do the job.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to extract line of a file

Ok .. This is driving me nuts. I suppose I need another set of eyes. Example Data interface Vlan1 description xxxxxxxxxxxx ip address no ip redirects no ip proxy-arp ip flow ingress ip pim sparse-mode load-interval 30 ! interface Vlan2 ... (5 Replies)
Discussion started by: popeye
5 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

sed to replace a line with modified line in same file

i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..? i have come up till the below code sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
Discussion started by: vivek d r
5 Replies

4. Shell Programming and Scripting

copying a line from a file using sed

Hi All, I need to copy a specific line from a file to another file. lets suppose the line number 13 of a file when I am writing the line number explicitly.. its working fine sed -n '13p' afile > anotherfile but, when inside a script, i am getting the line number value inside a variable... (4 Replies)
Discussion started by: gotamp
4 Replies

5. Shell Programming and Scripting

Extract a number from a line in a file and sed in another copied file

Dear all, I am trying to extract a number from a line in one file (task 1), duplicate another file (task 2) and replace all instances of the strings 300, in duplicated with the extracted number (task 3). Here is what I have tried so far: for ((k=1;k<4;k++)); do temp=`sed -n "${k}p"... (2 Replies)
Discussion started by: mnaqvi
2 Replies

6. Shell Programming and Scripting

how to use sed for reading from a file, line by line?

I have a file, from where I need to extract some data. But, the condition is like following : The script will read line by line,while checking if any line starts with 'MN'. If found true, it looks for if the immediate line starts with 'PQ' or not. If its true then, extract few fields from that... (1 Reply)
Discussion started by: mady135
1 Replies

7. Shell Programming and Scripting

sed to read line by line and input into another file

I have two files. Fileone contains text string one text string two text string three Filetwo contains Name: Address: Summary: Name: Address: Summary: Name: Address: Summary: I would like to use sed to read each line of file one and put it at the end of the summary line of file... (3 Replies)
Discussion started by: dolacap
3 Replies

8. Shell Programming and Scripting

Sed grabbing the last line of a file

I can grab the first line w/ sed how do you grab the last line of a file? (2 Replies)
Discussion started by: xgringo
2 Replies

9. Shell Programming and Scripting

Replace a line in a file with sed

Hi, I am trying to write a script that will replace "PermitEmptyPasswords yes" with "PermitEmptyPasswords no". The following does not seem to work: - sed 's!/"PermitEmptyPasswords yes"/!/"PermitEmptyPasswords no"/!' Appreciate any ideas. Thanks (2 Replies)
Discussion started by: mtech3
2 Replies

10. Shell Programming and Scripting

delete line in file with sed

sed "/$titlesearch/d" movielist will delete any line in the file movielist that matches $titlesearch, but this is only a screen print correct ? how can I have sed to actually delete the line from the file so that it doesnt appear next time I open the file ? thanks Steffen (8 Replies)
Discussion started by: forever_49ers
8 Replies
Login or Register to Ask a Question