[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert  6 digits into a chart

Posted on 2006-04-03
6
Medium Priority
?
305 Views
Last Modified: 2010-04-21
Nee help in :
1.  add my 6 figure into my chart
2.  delete  name in a chart
66666  Gustavson        Ian     25      M       250000
88888 Anderson  Jane    Jane    38      F
need to delete the 1st Jane and insert 450000 under 250000.  Please help me the chart should look like this
66666  Gustavson        Ian     25      M       250000
88888  Anderson        Jane    38      F        450000

Please help!!!!!!!!!!
0
Comment
Question by:leftridge1
6 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 1200 total points
ID: 16365992
perl -i -pe 's/Jane\s+(Jane.*)/$1\t450000/' chart
0
 

Author Comment

by:leftridge1
ID: 16366247
when i put in the command it came out like this
66666  Gustavson        Ian     25      M       250000
88888 Anderson  Jane  38       F       450000
Is there any way I can add space to line the chart up.  
0
 
LVL 7

Assisted Solution

by:XoF
XoF earned 400 total points
ID: 16367486
awk '{ if ($3~/Jane/) {print $1"\t"$2"\t"$4"\t"$5"\t"$6"\t450000" }else {print $0}}' <file>

if input isn't tab-separated, try this one:
awk '{ if ($3~/Jane/) {print $1"\t"$2"\t"$4"\t"$5"\t"$6"\t450000" }else {print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}}' <file>

bye,

-XoF-
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 400 total points
ID: 16370036
another variant:
awk '($4=="Jane"){$4=$5;$5=$6;$6="450000";}{printf("%-6s%-16s%-8s%-8s%-8s%s\n",$1,$2,$3,$4,$5,$6);}' chart
0
 
LVL 7

Expert Comment

by:XoF
ID: 16375732
btw:
Perhaps one of you has an idea (according to the given awk-suggestions, I guess not...;) ):
I was just wondering, whether awk provides a kind of "shift-operator" for the postional params/matches....
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16375893
> .. awk .. "shift-operator"
unfortunately no, at least I don't know of any
sometimes your simply can set a positional parameter "empty, like $3=""; but that is gawk/nawk only
otherwise you have to loop
  for(i=start;i<=NF;i++){$(i-1)=$i;}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question