Login or Register to Ask a Question and Join Our Community


Shell Script with following awk command pls help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script with following awk command pls help
# 1  
Old 10-25-2016
Shell Script with following awk command pls help

Hi

I want to create a shell script with the following awk command & also get the filenames in output.

Code:
awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' *.xml

As there will be multiple outputs related to many xml files I cannot identify which output belongs to which file

can anyone help?



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

Last edited by RudiC; 10-25-2016 at 10:30 AM.. Reason: Added CODE tags.
# 2  
Old 10-25-2016
Hello sharp488,

Welcome to forums, could you please try following and let me know if this helps.
Code:
for file in *.xml
do
    echo "File name which is processing currently: " $file
    awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' $file 
    echo "******************************"
    echo ""
done

Thanks,
R. Singh
# 3  
Old 10-25-2016
Its giving me error
Code:
$ ./roottelnet.sh
./roottelnet.sh: line 2: syntax error near unexpected token `$'do\r''
'/roottelnet.sh: line 2: `do


Moderator's Comments:
Mod Comment Please use CODE tags for output data as well as required by forum rules!

Last edited by RudiC; 10-25-2016 at 10:32 AM.. Reason: Added CODE tags.
# 4  
Old 10-25-2016
Quote:
Originally Posted by sharp488
Its giving me error
$ ./roottelnet.sh
./roottelnet.sh: line 2: syntax error near unexpected token `$'do\r''
'/roottelnet.sh: line 2: `do
Hello sharp488,

Seems you may have carriage characters in your script which you are using, could you please use following command to confirm the same.
Code:
cat -v  Input_file

Where Input_file is your script name. If you are seeing control M characters there like as an example as follows.
Code:
again test test1 test1 test2^M
test test test1 test chumma.^M

If you find above control M characters into your script then you could try following to remove them.
Code:
awk '{gsub(/\r/,X,$0);print}' roottelnet.sh > tmp_roottelnet.sh
mv tmp_roottelnet.sh  roottelnet.sh

Then you could try to run your script. Kindly do let us know if you have any queries on same.

Thanks,
R. Singh
# 5  
Old 10-25-2016
Try (untested):
Code:
awk '/<catetcsecuretty0>/ {p=1; print FILENAME ":"} /<catvarlogmessages0>/ {p=0} p' *.xml

# 6  
Old 10-25-2016
i did a vi on the file its showing
Code:
for file in *.xml
do
    echo "File name which is processing currently: " $file
    awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' $file
    echo "******************************"
    echo ""
done
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~

Image

---------- Post updated at 07:47 PM ---------- Previous update was at 07:41 PM ----------

Quote:
Originally Posted by RudiC
Try (untested):
Code:
awk '/<catetcsecuretty0>/ {p=1; print FILENAME ":"} /<catvarlogmessages0>/ {p=0} p' *.xml

Thank You.
Its working Smilie

Last edited by Don Cragun; 10-25-2016 at 04:21 PM.. Reason: Add missing CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

3. Shell Programming and Scripting

Need help with first shell script pls.

Hi, I'm trying to extract information from one file to update another one and am a bit stuck. the first file is made up of tags e.g. <item>a@b.com</item> jksdhfjkdsh sldkjfds l klsjdf <item> c@d.com </item> what i'd like to do is extract the email addresses between these tags,... (6 Replies)
Discussion started by: newb1000
6 Replies

4. Shell Programming and Scripting

Error in Shell Script - Can anyone help Pls

Please find my shell script below ------------------------------------- #!/usr/bin/ksh ORAUSER=$1 P_REQUEST_ID=$4 current_time=`date +%m%d%y.%H%M%S` echo "Process started at `date +%m/%d/%y.%H:%M:%S`" #Intialize Variables export SHLIB_PATH=/usr/local/lib ext=".pdf" ps_ext=".ps"... (4 Replies)
Discussion started by: uuuunnnn
4 Replies

5. Shell Programming and Scripting

shell script, pls help

# for i in `cat oo`;do ls -ld $i;done ls: /var/tmp/i: No such file or directory ls: i: No such file or directory ls: /var/tmp/ii: No such file or directory ls: i: No such file or directory ls: /var/tmp/iii: No such file or directory ls: i: No such file or directory ls: /var/tmp/iiii: No such... (2 Replies)
Discussion started by: cpttak
2 Replies

6. Shell Programming and Scripting

Shell Script Required? Pls. help me

Hi All, I have Information in the file like, ============ Interface Information ==================== +++++++++++++++++ NMInterface ++++++++++++++ ObjID:251c55a2-2257-71dd-0f68-9887a1f10000 NNMObjID:82857 EntityName:aust00m1.mis.amat.com ] Description:ATM9/0/0-atm layer Discovered in... (22 Replies)
Discussion started by: ntgobinath
22 Replies

7. Shell Programming and Scripting

Shell Script Requirements pls

Moderators note: This user has been banned for persistent rule breaking despite being warned that this would be the result. (0 Replies)
Discussion started by: tt1ect
0 Replies

8. Shell Programming and Scripting

Passing value from shell script to .pls file

I have a shell script which takes at the command prompt options like ss1.sh -F SCOTT -T JOHN F- From User T- To User I want to pass the From User(SCOTT) Value to another script ss2.pls (This script runs a PL/SQL Program). Depending on the FromUser value in the ss1.sh script i have to... (4 Replies)
Discussion started by: dreams5617
4 Replies
Login or Register to Ask a Question

Featured Tech Videos