How to separate a line with or without using newline command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to separate a line with or without using newline command?
# 1  
Old 05-18-2010
How to separate a line with or without using newline command?

Hi,
I am using Putty for unix shell scripting. I need some suggestions in splitting the 'output line' into two separate lines. Originally I am getting the input from another text file A. And when looking at the content in the text file A, the lines are separated in the way I want. After that I am passing the contents of the text file A to the text file B. The text file B already has some output data in it. All I want is to merge the text from file A into file B. I succeed in doing so but the contents from file A are now displayed in same line in text file B.

For Example:
In Text file A: / abc not found
/ def not found
/ ghi not found

But when it is copied to text file B, it looks like,

The missing items are:
/ abc not found / def not found / ghi not found

But I want the output file in this format:
The missing items are:
/ abc not found
/ def not found
/ ghi not found

Thanks!!!
# 2  
Old 05-18-2010
How did you copy fileA to fileB?

Try this
Code:
cat fileA >> fileB

# 3  
Old 05-18-2010
Thanks! Yes, I have used the 'cat' command and it is not working as I expected.

---------- Post updated at 12:28 PM ---------- Previous update was at 12:20 PM ----------

Do u guys think using an incremental loop is a good idea for this question? That is, in the text file A whenever a '/' occurs then we have to put it in next line. Do you guys know hoe to implement this procsdure? Or is there any better way to split the lines?

I will appreciate your suggestions/help...
# 4  
Old 05-18-2010
Quote:
Originally Posted by snr100
I am using Putty for unix shell scripting.
What is your shell? That is no the same thing as PuTTY, the shell runs on the server.
# 5  
Old 05-18-2010
It is Ksh...Korn shell scripting
# 6  
Old 05-18-2010
Quote:
Originally Posted by snr100
Do u guys think using an incremental loop is a good idea for this question? That is, in the text file A whenever a '/' occurs then we have to put it in next line. Do you guys know hoe to implement this procsdure? Or is there any better way to split the lines?
sed 's#/#/\n#g' < infile > outfile

Last edited by Corona688; 05-18-2010 at 02:40 PM.. Reason: fix typo
# 7  
Old 05-18-2010
Hi Corona,
Thanks for your reply. I used your suggestions in my code but it doesn't seem to bring my desired result.

After applying your code the output looked like this,
// abc not found // def not found // ghi not found

But I want output in the following format,
// abc not found
// def not found
// ghi not found

Thanks! Any suggestions!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting an unexpected newline in my while loop line-by-line feed

Hi, I'm trying to get a line returned as is from the below input.csv file in Bash in Linux, and somehow I get an unexpected newline in the middle of my input. Here's a sample line in input.csv $> more input.csv TEST_SYSTEM,DUMMY@GMAIL.COM|JULIA H|BROWN And here's a very basic while loop... (7 Replies)
Discussion started by: ChicagoBlues
7 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. Shell Programming and Scripting

Add newline before another line of occurance

Hi , I have a file like I want to add a new line before "Realized" only when it comes after "Sheep". There may be any line betwwen "Sheep" and "Realized" other than this two. Say my new line is "a goat", so the desired result would be Can any body help me in this? thanks (10 Replies)
Discussion started by: arup1980
10 Replies

4. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

5. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

6. UNIX for Dummies Questions & Answers

Print a newline after first match in line

Hi everyone I have a file where CP occurs both within each line and at the very end: dwer 17 knsdask= * CP hwla 17 h'wopie un CP I would like to separate the line on the first CP to get: dwer 17 knsdask= * CP hwla 17 h'wopie un CP What I have so far is: awk '{for (x=1; x<NF; x++) ... (5 Replies)
Discussion started by: meet77
5 Replies

7. Shell Programming and Scripting

Read each line and saving the line in separate files

Hi Experts, I am having a requirement like this; Input file EIM_ACCT.ifb|1001|1005 EIM_ADDR.ifb|1002|1004 EIM_ABD.ifb|1009|1007 I want to read each line of this file and pass each line,one at a time,as an argument to another script. eg; 1.read first line->store it to a file->call... (2 Replies)
Discussion started by: ashishpanchal85
2 Replies

8. Shell Programming and Scripting

[Solved] making each word of a line to a separate line

Hi, I have a line which has n number of words with separated by space. I wanted to make each word as a separate line. for example, i have a file that has line like i am a good boy i want the output like, i am a good (8 Replies)
Discussion started by: rbalaj16
8 Replies

9. Shell Programming and Scripting

Replace a line with a separate line in code

I have a bunch of files that are like this: <htmlstuffs>HTML STUFFS</endhtmlstuffs> <h1>Header</h1> <htmlstuffs>HTML STUFFS</endhtmlstuffs> <h1>Unique</h1> <html stuffs>HTML STUFFS</endhtmlstuffs> And Here's what I'd like it to look like: <htmlstuffs>HTML STUFFS</endhtmlstuffs>... (2 Replies)
Discussion started by: kason
2 Replies

10. Shell Programming and Scripting

use regexp to insert newline within a line

I have successfully used regexp and sed to insert a newline before or after a line containing a matched pattern /WORD/. However, I want to insert a newline immediately following /WORD/ and not after the -line- containing the pattern matched. I can match a pattern, but it is matched via a wild card... (2 Replies)
Discussion started by: kpeirce
2 Replies
Login or Register to Ask a Question