Shell script to extract data in a file

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Shell script to extract data in a file
# 15  
Old 02-16-2017
Use a redirection like awk '...' file > outputfile
# 16  
Old 02-16-2017
@ Rudic,

Below it's my screen, when i tried to run. I created a vi file called output.awk, wrote your code in it, then gave the root permissions to the file, then executed with sh output.awk, i got an error awk not found.


Code:
"output.awk" [New file] 24 lines, 815 characters
[gil@cx01:~]$
>chmod 777 output.awk
[gil@cx01:~]$
>ls -la
total 9570034
drwxr-xr-x   2 bscscx   bscs           4 Feb 16 12:25 .
drwxr-xr-x   8 bscscx   bscs          19 Feb 16 08:12 ..
-rw-r--r--   1 bscscx   bscs     4895889520 Feb 16 08:37 input
-rwxrwxrwx   1 bscscx   bscs         815 Feb 16 12:25 output.awk
[gil@cx01:~]$
>sh output
output.awk: wk: not found


Moderator's Comments:
Mod Comment Seriously: PLEASE use CODE tags as required by forum rules!

Last edited by RudiC; 02-16-2017 at 08:17 AM.. Reason: Added CODE tags.
# 17  
Old 02-16-2017
As I can't see that file's contents, I can't comment. There's no wk command in my script. Trying to replicate what you describe (a file with the script in post#6 as is), I find it works perfectly.
Did you consider the hint in post#11?
# 18  
Old 02-16-2017
Did you NOT read RudiC's post #11?

Why not try to find it using the which command?

And why are you using '777' for your 'output.awk' file?
# 19  
Old 02-16-2017
Quote:
Originally Posted by gillesi
@ Rudic,

Below it's my screen, when i tried to run. I created a vi file called output.awk, wrote your code in it, then gave the root permissions to the file, then executed with sh output.awk, i got an error awk not found.


Code:
"output.awk" [New file] 24 lines, 815 characters
[gil@cx01:~]$
>chmod 777 output.awk
[gil@cx01:~]$
>ls -la
total 9570034
drwxr-xr-x   2 bscscx   bscs           4 Feb 16 12:25 .
drwxr-xr-x   8 bscscx   bscs          19 Feb 16 08:12 ..
-rw-r--r--   1 bscscx   bscs     4895889520 Feb 16 08:37 input
-rwxrwxrwx   1 bscscx   bscs         815 Feb 16 12:25 output.awk
[gil@cx01:~]$
>sh output
output.awk: wk: not found

Moderator's Comments:
Mod Comment Seriously: PLEASE use CODE tags as required by forum rules!
As I already noted in here....
Save the code post 5 in a file called gil.awk and execute it as awk -f gil.awk input > output
I'm not sure how much easier the explanation can be....
Where exactly are you stuck?

Last edited by vgersh99; 02-16-2017 at 11:03 AM..
# 20  
Old 02-16-2017
@Rudic, please i'm very new with this. Below your code, just how i wrote it on my file. I created a vi file called gil. In it i put your code, and then i executed it as a sh script with sh filename(gil) command. My input file is DS2_export100217.ldif, and i redirect the result in an output file called output. Please tell me if i did something wrong.

Code:
awk -F: '
BEGIN                   {HD="MSISDN,IMSI,NAM,TS11,TS21,TS22,TS62,BAIC,BAOC,APNID1,APNID2"
#                        print HD
                         HDCnt  = split(HD, HDArr, ",")
                         NXTREC = "dn"
                         HDCM   = ","HD","
                        }

#                       {gsub (/[\t ]*|\*/, "", $1)}

$1 == NXTREC && PR      {for (i=1; i<=HDCnt; i++) printf "%s,", RES[HDArr[i]]
                         printf RS
                         delete RES
                        }

$1 == NXTREC            {PR=1}

HDCM ~ "," $1 ","       {RES[$1]=$0
                        }

END                     {for (i=1; i<=HDCnt; i++) printf "%s,", RES[HDArr[i]]
                         printf RS
                        }
' FS=":" OFS="," DS2_export100217.ldif >> output

# 21  
Old 02-16-2017
This doesn't match what you posted in post#16.
As I said in post#17, when I do exactly what you describe in post#20, I don't have a problem, a file "output" is created with the expected contents.

What's your OS, shell, and awk versions? Any error messages when you run your approach?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to extract data from csv file

Hi everyone, I have a csv file which has data with different heading and column names as below. Static Data Ingested ,,,,,,,,,,,,Known Explained Rejections Column_1,column_2,Column_3,Column_4,,Column_6,Column_7,,% Column_8,,Column_9 ,Column_10 ,... (14 Replies)
Discussion started by: Vivekit82
14 Replies

2. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 7 columns having values say column 1,column 2.....column 7 as below along with their values. Name, Address,... (7 Replies)
Discussion started by: Vivekit82
7 Replies

3. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

4. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

5. Shell Programming and Scripting

need a shell script to extract data from a log file.

If I have a log like : Mon Jul 19 05:07:34 2010; TCP; eth3; 52 bytes; from abc to def Mon Jul 19 05:07:35 2010; UDP; eth3; 46 bytes; from aaa to bbb Mon Jul 19 05:07:35 2010; TCP; eth3; 52 bytes; from def to ghi I will need an output like this : Time abc to def... (1 Reply)
Discussion started by: hitha87
1 Replies

6. Shell Programming and Scripting

Need shell script to extract data from oracle database

shell script (4 Replies)
Discussion started by: frns5
4 Replies

7. Shell Programming and Scripting

Help with shell script to extract data from XML file

Hello Scripting Gurus, I need help with extracting data from the XML file using shell script. The data is in a large XML and I need to extract the id values of all completedworkflows. Here is a sample of it. Input and output data is also in the attached text files. <wfregistry>... (5 Replies)
Discussion started by: yajaykumar
5 Replies

8. Shell Programming and Scripting

shell-script which extract data from log file

give me a shell-script which extract data from log file on a server by giving date and time as input (for both start time and end time) and it will give the logs generated during the given time as output. (4 Replies)
Discussion started by: abhishek27
4 Replies

9. Shell Programming and Scripting

extract data from xml- shell script using awk

Hi, This is the xml file that i have. - <front-servlet platform="WAS4.0" request-retriever="SiteMinder-aware" configuration-rescan-interval="60000"> <concurrency-throttle maximum-concurrency="50" redirect-page="/jsp/defaulterror.jsp" /> - <loggers> <instrumentation... (5 Replies)
Discussion started by: nishana
5 Replies

10. Shell Programming and Scripting

How to extract data using UNIX shell script?

Hello All, I am starting with UNIX. Any help is highly appreciated. How to extract data using UNIX shell script? And how do you export data using UNIX shell scripts into Microsoft Excel format? Thank you. (3 Replies)
Discussion started by: desiondarun
3 Replies
Login or Register to Ask a Question