Help with changing text file layout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with changing text file layout
# 1  
Old 11-26-2012
Help with changing text file layout

Hi there,
I am with this one column input text file to change layout, please help. Thanks. I have awk, sed.

$ cat input
Code:
Median
1.0
2.3
3.0

Median
35.0
26.3
45.7
10.1
63.1

Median
1.2
2.3
3.4
4.5

And the desire output should be
Code:
Median 1.0 2.3 3.0
Median 35.0 26.3 45.7 10.1 63.1
Median 1.2 2.3 3.4 4.5

# 2  
Old 11-26-2012
try:
Code:
awk ' /^ *$/ {print} !/^ *$/ {printf $0 " "} END {print ""}' input

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 11-26-2012
Code:
awk '/^$/ {print }
       /^[M0-9]/ {printf ("%s ", $0) }
       END {print ""} ' inputfile > newfile

This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 11-26-2012
It's an awk buffet:

Code:
awk '/Median/{if(NR!=1)print " ";}{printf("%s ", $0)}END{print " ";}' file

This User Gave Thanks to in2nix4life For This Post:
# 5  
Old 11-26-2012
more for the smorgasbord:
Code:
awk '{printf ($0 ~ /^ *$/) ? "\n" : $0 " " } END {print ""}' input

or, look Ma! no awk!
Code:
while read line
do
  printf "$line "
  [ -z "$line" ] && echo ""
done < input
echo ""

This User Gave Thanks to rdrtx1 For This Post:
# 6  
Old 11-27-2012
Thank you so much. They all work! Really appreciate all the helps!

I really need to learn more about regular expressions...
# 7  
Old 11-27-2012
Or

Code:
awk 'NR>1{gsub("\n"," ",$0);print "Median "$0}' RS="Median" file

This User Gave Thanks to pamu 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

Add delimiter to a file from layout file

I need to add delimiter in file abc.txt using layout.txt for eg 1 to 2 is category field so after that I need to add delimiter ~ abc.txt 110101160315100000000000000 110101160315100000000000000 Layout.txt CATEGORY POSITION (1:2) char, 2 GROUP_ID ... (8 Replies)
Discussion started by: lalitpct
8 Replies

2. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

3. UNIX for Dummies Questions & Answers

Changing text in multiple files, but with different text for each file

Hello, I have a situation where I want to change a line of text in multiple files, but the problem is that I want to change the text to something unique for each file. For example, let's say I have five files named bob.txt, joe.txt, john.txt, tom.txt, and zach.txt. Each of these files has a... (5 Replies)
Discussion started by: Scatterbrain26
5 Replies

4. UNIX for Dummies Questions & Answers

Changing table layout

Hi everyone, I'm a beginner in Unix, and would need some help from you guys! My input (pipe delimited): City|ZIP|Ref. Item NYC|212|00004 NYC|212|00032 NYC|212|00006 LA|90049|00068 LA|90049|00009 SF|94131|0027 You can see that the first 3 lines have column 1 and 2 in common, same for... (8 Replies)
Discussion started by: beca123456
8 Replies

5. Shell Programming and Scripting

Changing a text file

I have a file as below and want to change it using awk I want to find the entries such as Iteration No.788 Best Value 0.00408152 Next-Worst Value 0.00522935 Worst Value 0.00523487 and change it to Iteration No.788 788. Best Value = 0.00408152 788. ... (8 Replies)
Discussion started by: kristinu
8 Replies

6. Shell Programming and Scripting

CHANGING THE TEXT INSIDE A FILE

Hi All, I need a small help in formating a file. I have a file with word like this; ATGHYJIKOLFHJDHDGDYFGFYGRYGFYRHFYHFUED DHDJFDFSJFLFJSKJFSLKJFGHDKLGLDKGLKDNVNV VNLDVLDVDHFJDKDJVNVHSUFNHJFMVJFMVKJMFV ... .... ....like this 75000 words. I want to convert this words into a single... (5 Replies)
Discussion started by: Lucky Ali
5 Replies

7. Shell Programming and Scripting

Changing the text file format

Hi, I have a shell script to unload all the empname who have salary >50000 from the emp table into a text file(empname.txt) . m_db unload "$dbc_file" -column_delimiter ',' -select "SELECT empname FROM emp where salary > 50000" >> empname.txt Now my text file have data in the following format ... (3 Replies)
Discussion started by: kavithakuttyk
3 Replies

8. Linux

Changing default keyboard layout in Linux

Hi I have Fedora linux with XFCE desktop. I want to use Indic lanquage in that. I have installed unicode devnagri fonts. But I am not able to change my default keyboard layout. How can I change default keyboard layout in XFCE or through command line. Thanks NeeleshG (0 Replies)
Discussion started by: neel.gurjar
0 Replies

9. UNIX for Dummies Questions & Answers

Changing Keyboard layout

Hi, How do i go about changing the keyboard layout to the UK layout. currently the @ symbol on the keyboard appears as a " sybol on the monitor. Many Thanks in advance Kam (1 Reply)
Discussion started by: vishnura
1 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question