Line break on word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line break on word
# 1  
Old 10-25-2011
Line break on word

I have a file that contains the following:
Code:
^field LINE_1     data
^field LINE_2     data
^field LINE_3     data
^field LINE_4     data
^field LINE_5     data 
...

And im looking to do a line break at the end of the number before the text to make it look like this
Code:
^field LINE_1    
data
^field LINE_2     
data
^field LINE_3     
data
^field LINE_4     
data
^field LINE_5     
data

I have been unsuccesfully searching all day, any help woudl be great
Thanks

Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by zaxxon; 10-25-2011 at 10:33 AM.. Reason: code tags, see PM
# 2  
Old 10-25-2011
You can try below
Code:
 
awk '{print $1" "$2"\n"$3}' input_file > output_file

Regards,
Vishal
# 3  
Old 10-25-2011
Thank you vishalaswani
that is 99% there!
It chopps it off at the first word after the break, if i have a line with 20 words on it, how do i make it read to the end?
# 4  
Old 10-25-2011
Should it always put the last word in the next line, no matter how many words there are?
# 5  
Old 10-25-2011
Yes
If the line was to say "THIS IS ALL YOUR TEXT" i would need it to have all of it and not just the first word
# 6  
Old 10-25-2011
I do not understand that explanation, but you can try this:
Code:
awk '{$NF=RS $NF; print}' infile

In case that is not what you are looking for, post your complete example input and an example output using [code] and [/code] tags, thanks.
# 7  
Old 10-25-2011
Sorry for the confusion, if i was to have this:

Code:
^field LINE_22    
^field LINE_23      BILLING     CREDIT   AVAILABLE     PAST DUE       MINIMUM     TOTAL DUE
^field LINE_24         DATE      LIMIT      CREDIT                    PAYMENT
^field LINE_25     00-00-00          0           0          .00           .00           .00
^field LINE_26     00-00-00          0           0          .00           .00           .00

i would like the final output to be:
Code:
^field LINE_22  
  
^field LINE_23
      BILLING     CREDIT   AVAILABLE     PAST DUE       MINIMUM     TOTAL DUE
^field LINE_24 
        DATE      LIMIT      CREDIT                    PAYMENT
^field LINE_25 
    00-00-00          0           0          .00           .00           .00
^field LINE_26 
    00-00-00          0           0          .00           .00           .00

Does that help?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

2. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

3. Shell Programming and Scripting

For loop to break apart word

notimes=5 word=excellency the word excellency contains 10 letters. 10 letters divided by 2 = 5. which means, 5 two-groups of letters are in the word excellency. i need to perform a function on each group of letters. but the only thing i can think of is the following, which i just know... (5 Replies)
Discussion started by: SkySmart
5 Replies

4. Shell Programming and Scripting

break the string and print it in a new line after a specific word

Hi Gurus I am new to this forum.. I am using HP Unix OS. I have one single string in input file as shown below Abc123 | cde | fgh | ghik| lmno | Abc456 |one |two |three | four | Abc789 | five | Six | seven | eight | Abc098 | ........ I want to achive the result in a output file as shown... (3 Replies)
Discussion started by: kannansr621
3 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. Shell Programming and Scripting

sed: break before word if it's not last on the line

I've been trying this, and can't get it right. I want to put a line break before a word, but only if it's *not* the last word in the line. So if the break work was "fish," then... We want to fish tomorrow ...would become... We want to fish tomorrow ...but this line would remain... (3 Replies)
Discussion started by: estebandido
3 Replies

8. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

9. UNIX for Dummies Questions & Answers

regular expression for replacing the fist word with a last word in line

I have a File with the below contents File1 I have no prior experience in unix. I have just started to work in unix. My experience in unix is 0. My Total It exp is 3 yrs. I need to replace the first word in each line with the last word for example unix have no prior experience in... (2 Replies)
Discussion started by: kri_swami
2 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question