Applying awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Applying awk
# 1  
Old 11-30-2013
Applying awk

I have a file that is formatted like this:
Code:
========
aaaa  11111
bbbb  2222
cccc   3333
============
dddd  4444
eeee  5555
ffff     6666
============

trying to get the file to look like this:
Code:
======
aaaa  aaaa 1111
aaaa bbbb 2222
aaaa cccc 3333
=============
dddd dddd 4444
dddd eeee 5555
dddd ffff 6666
============

so want the 1st word to become a column but only between the = signs. Have this awk line but can't figure out how to make it work for each group between the = signs.
Code:
awk 'NR==1 {T=$1} {print T, $0}' file

# 2  
Old 11-30-2013
We have helped you find solutions to 17 other problems you have posted on these forums, but you don't seem to be picking up how to adapt the code we've shown you to work for very similar problems.

In addition to showing us the input you have and the output you want, try writing an algorithm in English that describes how to convert the input you have into the output you want. Then see if you can implement that algorithm with a shell script or an awk script.

It is OK if you can't complete the code, but you should be able to describe the steps that need to be taken. If you have a good description of the steps that need to be taken, it is much easier to write a program to do what needs to be done.

We want to help you learn how to program; not act as a free programming house to write your software for you.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 11-30-2013
@ Don I was about to post answer, you are right let him learn, will see what he tried so far.

------edit-------------

for input given in post #1

Code:
$ awk '/^\=/{print ; x = getline != 0 ? $1 : NULL }x{ print x, $0 }' file
========
aaaa aaaa  11111
aaaa bbbb  2222
aaaa cccc  3333
============
dddd dddd  4444
dddd eeee  5555
dddd ffff  6666
============

Next time I am not going to answer,till you show your effort towards it..this is the best opportunity to learn, so take advantage of it. don't just copy paste.. I hope you followed what Don said.

Last edited by Akshay Hegde; 11-30-2013 at 02:03 AM..
This User Gave Thanks to Akshay Hegde For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Debian

Applying patch for Samba version 4.1.17

The version of Samba in our billing server is 4.1.17-Debian. I have been reminded by our management to implement the patch for Samba on this server. However, I am not sure how to implement the patch. I have browsed some websites for the correct patch to implement for Samba 4.1.17, and the patch... (11 Replies)
Discussion started by: anaigini45
11 Replies

2. Ubuntu

Recompile the kernel after applying a patch in Ubuntu.

I have applied a patch using this command: patch -p1 < (file) then I did git commit -a. Now I want to recompile the kernel for making this patch live. Should I use make oldconfig or make localmodconfig After that, make -j$(grep -c "processor" /proc/cpuinfo) sudo make... (1 Reply)
Discussion started by: BHASKAR JUPUDI
1 Replies

3. Shell Programming and Scripting

Applying the same awk over a directory of files with individual file output

I am trying to apply an awk action over multiple files in a directory. It is a simple action, I want to print out the 1st 2 columns (i.e. $1 and $2) in each tab-separated document and output the result in a new file *.pp This is the awk that I have come up with so far, which is not giving me a... (6 Replies)
Discussion started by: owwow14
6 Replies

4. Shell Programming and Scripting

Help need in applying logic in one script

Hello Experts, (1 Reply)
Discussion started by: shams.abbazi@gm
1 Replies

5. UNIX for Dummies Questions & Answers

applying unix command in EBCIDIC file

Hi, I'm having a general query. If we do cat <file name> on a Ebcidic format file then many unknown characters are displayed in my screen. Can we change the character set related to EBCIDIC in session level and apply the cat command on a EBCIDIC file? By doing so can we able to see the... (2 Replies)
Discussion started by: poova
2 Replies

6. AIX

applying patches in aix 5.3

Hi Admins, Basically i am HPUX guy.HP will release patch bundles every three months and the same we are applying on servers as proactive steps. Please let me know how it happens with AIX. My servers are AIX 5.3 with TL 10 and some are TL 7. These servers are installed 2 years back and... (1 Reply)
Discussion started by: newaix
1 Replies

7. Programming

Applying filters

I have a value X, a value DX and an odd integer N (say N=9) and want to create an array such that let X = 10, DX = 2 and N = 9 DIST(1) = X - 4 * DX DIST(2) = X - 3 * DX DIST(3) = X - 2 * DX DIST(4) = X - DX DIST(5) = X DIST(6) = X + DX DIST(7) = X + 2 * DX DIST(8) = X + 3 * DX DIST(9)... (2 Replies)
Discussion started by: kristinu
2 Replies

8. Programming

Applying a filter function

I have an L point filter flt which I need to apply to an array fin length N, the result being stored in fout. The filter will start shifting until one gets to the last element of fin. How can I do this. I ma getting quite confused. :wall: I got an array of indices ixa and ixb which give the... (2 Replies)
Discussion started by: kristinu
2 Replies

9. Shell Programming and Scripting

Applying lock on a file in Unix Ksh

Hi, How can we apply lock on a text file through Unix Ksh script. I did found a command flock (file descriptor) but am not very acquainted with the usage. Can anybody tell me if I need to use Flock command for applying locks to a file while writing on it. If the person can explain the usage... (3 Replies)
Discussion started by: kum5256
3 Replies
Login or Register to Ask a Question