awk/sed inserting muliple informations in one column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk/sed inserting muliple informations in one column
# 1  
Old 10-11-2012
awk/sed inserting muliple informations in one column

I'm probably sure I need to use either awk or sed judging by research but I'm not sure what exact command I have to do to do following...Smilie

So this is my text file
Code:
CPU 1 2 3 4 5 6
RAM 2 3 4 5 6 7
HAR  3 4 5 6 7 8

--------------
my input:
Code:
Cur_CPU=10
Cur_RAM=11
Cur_HAR=13

Desired Output:
Code:
CPU $Cur_CPU 1 2 3 4 5 6
RAM $Cur_RAM 2 3 4 5 6 7
HAR  $Cur_HAR 3 4 5 6 7 8

which would be
Code:
CPU 101 2 3 4 5 6
RAM 11 2 3 4 5 6 7
HAR  13 3 4 5 6 7 8

Thanks in advance

Last edited by Franklin52; 10-12-2012 at 05:32 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 10-11-2012
Not clear what you are trying to do..

How you want to give below inputs..?
to script or within a script itself..

Code:
Cur_CPU=10
Cur_RAM=11
Cur_HAR=13

# 3  
Old 10-11-2012
Sorry for my poor explanation Smilie
So, I have text file that is called performance.log that has following info
Code:
CPU 1 2 3 4 5 6
RAM 2 3 4 5 6 7
HAR  3 4 5 6 7 8

And with in the code, function generates following info
Code:
Cur_CPU=10
Cur_RAM=11
Cur_HAR=13

What I want to do is insert
Code:
Cur_CPU
Cur_RAM
Cur_HAR

to performance.log.
Cur_CPU will go to first row, second column
Cur_RAM will go to second row, second column
Cur_HAR will go to third row, second column

So that resulting performance.log would be
Code:
CPU 10 1 2 3 4 5 6
RAM 11 2 3 4 5 6 7
HAR  13 3 4 5 6 7 8

I hope this is clear....
(srry, i'm really terrible at explaining things )

Last edited by Franklin52; 10-12-2012 at 05:32 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 10-11-2012
Is this what you want..?


Code:
awk -v Cur_CPU=10 -v Cur_RAM=11 -v Cur_HAR=13 '/CPU/{$1=$1" "Cur_CPU}
/RAM/{$1=$1" "Cur_RAM}
/HAR/{$1=$1" "Cur_HAR}1' file

CPU 10 1 2 3 4 5 6
RAM 11 2 3 4 5 6 7
HAR 13 3 4 5 6 7 8

This User Gave Thanks to pamu For This Post:
# 5  
Old 10-11-2012
thanks it works fine! but it doesn't save to text file.... text file stays same after

Last edited by simonirang; 10-11-2012 at 12:04 PM..
# 6  
Old 10-11-2012
Quote:
Originally Posted by simonirang
thanks it works fine! but it doesn't save to text file.... text file stays same after
You need to rewrite the file...

try this...

Code:
awk -v Cur_CPU=10 -v Cur_RAM=11 -v Cur_HAR=13 '/CPU/{$1=$1" "Cur_CPU}
/RAM/{$1=$1" "Cur_RAM}
/HAR/{$1=$1" "Cur_HAR}1' file > temp_file

mv temp_file 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. UNIX for Beginners Questions & Answers

Awk/sed summation of one column based on some entry in first column

Hi All , I am having an input file as stated below Input file 6 ddk/djhdj/djhdj/Q 10 0.5 dhd/jdjd.djd.nd/QB 01 0.5 hdhd/jd/jd/jdj/Q 10 0.5 512 hd/hdh/gdh/Q 01 0.5 jdjd/jd/ud/j/QB 10 0.5 HD/jsj/djd/Q 01 0.5 71 hdh/jjd/dj/jd/Q 10 0.5 ... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies

3. Shell Programming and Scripting

Using sed in awk column

Hello, I need to translate a file with more thousand lines like thiszoneobjectrename "AAA_to_BBB"in a lineszoneobjectrename "AAA_to_BBB","AAA_BBB" I tried to using awk and sed in this manner but it don't workgrep _to_ Documenti/zoneSWITCH2 |awk '{print "zoneobjectrename " $2 "," $2= sed... (7 Replies)
Discussion started by: alen192
7 Replies

4. UNIX for Dummies Questions & Answers

Inserting text into a file with awk or sed

Hello, I've been trying to get a script working that fetches weather-data and converts it into an .ics file. The script works so far put I'm stuck at the point where I need to add specific static data. A thorough search through the forum did not point me into the right direction. #!/bin/bash... (3 Replies)
Discussion started by: Schubi
3 Replies

5. Shell Programming and Scripting

awk or sed: change the color of a column w/o screwing up column spacing

Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately. Here's some example output: Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop bond0 9 83830... (3 Replies)
Discussion started by: ryran
3 Replies

6. UNIX for Dummies Questions & Answers

Using awk/sed to determine whether there are any 2's, 3's and 4's in a column

Hi, I have a very large file which is of the general format: 0 3 4 2 ... 3 2 4 0 ... 0 3 4 2 ... 3 0 4 2 ... . . . . ... . . . . ... I would like to apply a simple awk/sed script to work out whether there are any 2's, 3's and 4's in each column. The results would look as... (3 Replies)
Discussion started by: kasan0
3 Replies

7. Shell Programming and Scripting

use sed on only column $3 with awk

I am using the command ls -lhB --group-directories-first --no-group --file-type --time-style=+%D $@ | sed 's/AlphaLexman/ALM/g' to replace my username with my initials (to keep the width shorter), but if my username is in the filename such asreport_by_AlphaLexman.txtit becomesreport_by_ALM.txt ... (2 Replies)
Discussion started by: AlphaLexman
2 Replies

8. Shell Programming and Scripting

Awk or Sed, fubd match in column, then edit column.

FILE A: 9780743551526,(Abridged) 9780743551779,(Unabridged) 9780743582469,(Abridged) 9780743582483,(Unabridged) 9780743563468,(Abridged) 9780743563475,(Unabridged) FILE B: c3saCandyland 9780743518321 "CANDYLAND" "MCBAIN, ED" 2001 c3sbCandyland 9780743518321 ... (7 Replies)
Discussion started by: glev2005
7 Replies

9. Shell Programming and Scripting

Cat 114 files using grep or awk to pull muliple fields

Files xxxxxxx.txt ------------------------------------------------------------------------------------------------------------------------------------ Req.By: xxxxxxx WABUSH MINES - xxxxxx MINE (1001) Page: 1 Run on: 12/14/09... (4 Replies)
Discussion started by: sctxms
4 Replies

10. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies
Login or Register to Ask a Question