Text editing/manipulation


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Text editing/manipulation
# 1  
Old 10-30-2019
Text editing/manipulation

Hello all.
I need to rearrange a very long text file with the following format.
The number of lines in each block is variable, but is between 1 and 10.

Any hints what command could I use for this?
Thank you.



Code:
  SAMPLE      2600
  15    3453  159   3970  486   4327  760   4498
  1215  4638  1620  4707  1927  4882  2280  4967
  2564  5079  2894  5284  3229  5441  3846  5678

Code:
  SAMPLE      2800
  23    3446  140   3831  308   4172  526   4374
  853   4568  1177  4638  1716  4746  2321  4963
  2604  5111  2823  5284  3045  5410  3917  5788
  4486  5985  5141  6195

The desired output format is:


Code:
2600 15     3453  159   3970  486   4327  760   4498
1215   4638  1620  4707  1927  4882  2280  4967
2564   5079  2894  5284  3229  5441  3846  5678
2800 23     3446  140   3831  308   4172  526   4374
853    4568  1177  4638  1716  4746  2321  4963
2604   5111  2823  5284  3045  5410  3917  5788
4486   5985  5141  6195

Moderator's Comments:
Mod Comment
Code tags please! (trying to figure out what went wrong with the png files included...)

Last edited by Neo; 10-30-2019 at 05:13 AM.. Reason: deleted poorly formatted images
# 2  
Old 10-30-2019
Try
Code:
awk '{ORS = RS} /SAMPLE/ {sub ($1 FS, ""); ORS = FS} 1' file

This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-30-2019
Thank you for your answer.
The example desired format I inserted earlier is displayed slightly differently to what was intended: the number copied from after the "SAMPLE" expression should be inserted not at the start of the first line, but as a new column, pushing the whole input text block out.

Thank you again.
# 4  
Old 10-30-2019
Try
Code:
awk '/SAMPLE/ {printf "%s", $2; next} {$0 = "\t" $0; print}'  file

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert vi editing to text editing

Dear Guru's I'm using Putty and want to edit a file. I know we generally use vi editor to do it. As I'm not good in using vi editor, I want to convert the vi into something like text pad. Is there any option in Putty to do the same ? Thanks for your response. Srini (6 Replies)
Discussion started by: thummi9090
6 Replies

2. UNIX for Dummies Questions & Answers

awk text editing

Dear all, I'm starting to learn programming, and I'm having some problem with awk text editing. I'm having a huge text file, and my goal is to print "something" before every 4th row starting from the second row. File example: AAAAA BBBBBB CCCCC DDDDD AAAAAAA BBBBBBBB CCCCCCC... (2 Replies)
Discussion started by: Higgo
2 Replies

3. Shell Programming and Scripting

Text manipulation help

Hello Unix.com, How can i generate links like this: i got http://upload.com/1/1.txt and i need to generate links from http://upload.com/1/1.txt to http://upload.com/1000/1000.txt Thanks in advance, Galford D. Weller (4 Replies)
Discussion started by: galford
4 Replies

4. UNIX for Dummies Questions & Answers

text manipulation help

Hello again unix.com How can I extract from a large file in format: steve@aol.com steve hawkins Location of this member is bla bla bla sun@hotmail.com Sun Ying This member is using browser bla bla bla to another text in format: steve@aol.com steve hawkins sun@hotmail.com sun ying ... (5 Replies)
Discussion started by: galford
5 Replies

5. Shell Programming and Scripting

[HELP] Text manipulation... [HELP]

I need to know how can I remove all word after comma on each line. Like: jjkj,iiuiui,ijlkjkij,ookoo kijljlj,jhhkj,ijijkijkj,oijkijj kjkljlkj,kjkjlkjlkj,opok,okop to jjkj, kijljlj, ... (5 Replies)
Discussion started by: slutb3
5 Replies

6. Shell Programming and Scripting

Editing text using AWK

France : 40 : John Persia : 50 : John -----Database What i am trying to achieve is to search for a book, and replave the title with the new title echo -n "Title:" read Title echo -n "Author:" read Author echo "new Title" read NewTitle awk 'BEGIN {... (11 Replies)
Discussion started by: gregarion
11 Replies

7. Shell Programming and Scripting

Text editing script does everything but edit text.

I wrote this script to create and edit a large number of websites based on a template site and a collection of text files which have the relevant strings in them delimited by colons. I run it and the shell doesn't produce any errors, but when it gets to the for loop where it actually has to edit... (2 Replies)
Discussion started by: afroCluster
2 Replies

8. Shell Programming and Scripting

text file editing

Hi, I need some help in text manipulation. I have an input file like this: 7629 "WPCW 19 - CW/AM1, WPCB 40 - FAMN/CORNER, WPCB-DT1 50 - FAMN/CORNER, " W35AW - Various Shopping Pgms W41CF - TBN W47CV - TBN WLLS-LP 49 - AM1 WATCH WPXI 11 N & WPIX 11 CW 1234 "WPCW 19 - CW/AM1,... (26 Replies)
Discussion started by: injeti
26 Replies

9. UNIX for Dummies Questions & Answers

Text editing on iPhone using ed

Hi all, I'm trying to edit a file using ed on an iphone. I am trying to edit a conf file and have managed to get to the directory where the default.conf file is located, however, when I type ed default.conf all i get is a number and then a blank line and a question mark which is why I am... (1 Reply)
Discussion started by: drewcifer
1 Replies

10. UNIX for Dummies Questions & Answers

Text Editing

Hello everybody, I have a sorted text file. some of the lines appear twice or even more. is there an unix utility that removes the extra appearences? Thanks, Ido. (7 Replies)
Discussion started by: ginodii
7 Replies
Login or Register to Ask a Question