Required Command in awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Required Command in awk command
# 1  
Old 07-02-2013
Oracle Required Command in awk command

Hi Firends,

I wanted to extract the first record of the file which starst with character say "X". And I tried an awk command which works when i try to execute it individually:

Code:
awk 'substr($1,1,1)=="X"' inputfile.txt

But when I use the same command in my script for which I am passing the parameters, it extracts the first record and the last record:

Code:
 awk 'substr($0,$1,$2)==$3' $File_Name >> /WorkingDirectory/Header_Trailor.txt

where $1 = Character Length
$2 = Character Position
$3 = Search String

Please help me on this regard. Suggessions will be helpful.

Thanks,
Ajay
Moderator's Comments:
Mod Comment please use code tags next time for your cade and data
# 2  
Old 07-02-2013
If you are passing these parameters, then define awk variables and use them:
Code:
awk -v s="$1" -v l="$2" -v c="$3" 'substr($0,s,l)==c' "$File_Name"

# 3  
Old 07-04-2013
Thanks a lot Yoda.. It worked.... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

2. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

3. Shell Programming and Scripting

Help Required regarding wc command

Hi guys, I want to find the number of records in a particular file and store that value in any other variable. I am trying this below command but it is not working and giving me an error "Uninary Operator Expected". say I have taken a variable name 'count' in which I have to store the no. of... (7 Replies)
Discussion started by: dtidke
7 Replies

4. Solaris

required command to know the port no.

Can anybody have the command to know the port no using unix command for the weblogic server application. (1 Reply)
Discussion started by: Amit_kolurwar
1 Replies

5. Shell Programming and Scripting

Help required using cut command

Hi all, I have one text as '/home/psv/file/test.ksh'. In that I want to cut the text as '/home/psv/file/' . Let me know which command to use. Thanks Mahalakshmi.A (4 Replies)
Discussion started by: mahalakshmi
4 Replies

6. UNIX for Dummies Questions & Answers

Help required on AWK command

I have two questions: (Q1) I am using a loop and want to print a particular field of a table using the AWK command by accessing one row at a time by validating NR with the loop counter. I am using a command like this but it isn't working! count=1 NAWK -F"|" -v var=$count 'NR == var { printf... (13 Replies)
Discussion started by: udiptya
13 Replies

7. UNIX for Dummies Questions & Answers

Help required for usermod command

Hi, I would need to modify my machine name : When i give "w" command, i am getting following message USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT krishnag pts/59 gunasekar 1:25pm 25:15 0.03s 0.03s -csh. My questions is, i need to change FROM (i.e... (1 Reply)
Discussion started by: gun
1 Replies

8. Shell Programming and Scripting

Help required for cat command

Hi, I had written the following script to find the list of files with *.ksh in a directory. and store it in a temp file. I want to loop through the file temp and list the contents. I had used cat temp. But its giving Cat and temp as the output. Do help me out. Thanks find .... (7 Replies)
Discussion started by: mahalakshmi
7 Replies

9. UNIX for Dummies Questions & Answers

Unix command help required

Hi All, Can anyone please help me in sort out the command to get the following command say File abc.log contains .... ...... This is the first line This is the second line This is the third line This is the fourth line This is the fifth line This is the first line This is the... (7 Replies)
Discussion started by: thaduka
7 Replies

10. Shell Programming and Scripting

Help required in grep command

Hi all, I need some help in grep command in a ksh script. Actually, i need to list all files having the file name like "BORD*.DAT" but exclude the files (from the list) having name like "BORD*mgt*.DAT". For that i used the following command: ls | grep "BORD*.DAT" | grep -v "BORD*mgt*.DAT" ... (4 Replies)
Discussion started by: panzer
4 Replies
Login or Register to Ask a Question