Please help to create script using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help to create script using awk
# 8  
Old 08-17-2010
in my file with columns say
a,b,c,d
a,s,d,f,g
1,2,3,45


whatever may in the second column replace it with another value say hai...any awk command....


please help
# 9  
Old 08-17-2010
Code:
nawk -F"," '$2="hai"' infile.txt

# 10  
Old 08-18-2010
thanks.....

my file name is say "file" and i have to remove the first line from this file and also replace the 3rd column with hai...i used awk 'NR>1' file..its working and again i used
nawk -F"," '$2="hai"' file..is there any way to execute these two in single line

---------- Post updated 08-18-10 at 02:53 AM ---------- Previous update was 08-17-10 at 08:32 AM ----------

my file has 5 cloumns say
A,1,2,3,4
B,1,2,3,4
C,1,2,3,4
D,1,2,3,4
My requirement is ,need to create a flat file from this file.the input file is csv format.
If the first line is A,then print col2,col3,col4 and each columns will have specified space ie:first print A then give 2 spaces,ie:A has 3 space,then 2nd col has 5 space,3rd col 7 space and 4th col10 space.check each row in the file.If the firat col is B,then print col2,col3 with col2 has 3 space and col3 has 15 space like that..please help

---------- Post updated at 03:32 AM ---------- Previous update was at 02:53 AM ----------

Hi all....please help to do the same...................thanks to allllllllllll
# 11  
Old 08-18-2010
Quote:
Originally Posted by Sanal
thanks.....

my file name is say "file" and i have to remove the first line from this file and also replace the 3rd column with hai...i used awk 'NR>1' file..its working and again i used
nawk -F"," '$2="hai"' file..is there any way to execute these two in single line


---------- Post updated 08-18-10 at 02:53 AM ---------- Previous update was 08-17-10 at 08:32 AM ----------

yes see below:
Code:
nawk -F"," 'NR>1&&$2="hai"' file

# 12  
Old 08-18-2010
thanks...it fine....please help me to solve this issue
my file has 5 cloumns say
A,1,2,3,4
B,1,2,3,4
C,1,2,3,4
D,1,2,3,4
My requirement is ,need to create a flat file from this file.the input file is csv format.
If the first line is A,then print col2,col3,col4 and each columns will have specified space ie:first print A then give 2 spaces,ie:A has 3 space,then 2nd col has 5 space,3rd col 7 space and 4th col10 space.check each row in the file.If the firat col is B,then print col2,col3 with col2 has 3 space and col3 has 15 space like that..please help

---------- Post updated at 05:39 AM ---------- Previous update was at 04:04 AM ----------

any suggestion please........................

---------- Post updated at 08:20 AM ---------- Previous update was at 05:39 AM ----------

Hi All...please help me to finish ..............thanksssssssssss

Last edited by Sanal; 08-18-2010 at 08:29 AM..
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 and sed script to create one output CSV file

Hi All , I would require your help to generate one output file after post processing of one CSV file as stated below This file is just a small cut from a big file . Big file is having 20000 lines PATTERN,pat0,pat1,pat2,pat3,pat4,pat5,pat6,pat7,pat8,pat9... (2 Replies)
Discussion started by: kshitij
2 Replies

2. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Using awk and sed to modify a create sql script

Hi, I have a file which contains the following data claim_src|clm_id,typ_id pat_src|pat_id prov_src|prov_id,clm_id,prov_name The first field is table name and second field is primary keys of the table Now I have three files which contain ddl of each table. clam_src.sql... (4 Replies)
Discussion started by: wahi80
4 Replies

4. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

5. Shell Programming and Scripting

Wrap lines with awk to create SQL script

Greetings! Some of my files list hardware errors (we test electronic components), some have none. If the file name has no errors, I still want to display a message like "No error", else I display the error from the file itself. I came up with this (with help) for myfile in `find . -name... (2 Replies)
Discussion started by: alan
2 Replies

6. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

7. Shell Programming and Scripting

Awk script to create new file based on previous line

Need help creating a script that does the following: Sort a file Compare the previous line "last field" with current line "last field" If they are the same, print output to a file If they are different print output to a new file The script should keep creating new files if the previous... (5 Replies)
Discussion started by: Muga801
5 Replies

8. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

9. Shell Programming and Scripting

create function with awk

hi all, i print four variable delimited by comma with awk : awk -F "," '{print $1;$2;$3;$4}' ' if $3="" code ... } i want to extract this information from another file using another awk using the $1 printed awk -v { code } but the problem i can't use two awk in the same code... (2 Replies)
Discussion started by: kamel.seg
2 Replies

10. Shell Programming and Scripting

help with awk to create report

Hi, I am trying to create a report using the following syntax: #!/bin/awk -f #script name: users_report BEGIN { FS=":" ; OFS="\t" ; print "User\tGID\tUser Name\tHome Dir\t" { print $1 , $3 , $5 , $6 } END { print "\n End of Report \n" } $> user_report /etc/passwd the output of... (5 Replies)
Discussion started by: ghazi
5 Replies
Login or Register to Ask a Question