Sponsored Content
Top Forums Shell Programming and Scripting awk : ORS not to be printed after the last record Post 302993925 by chandana.hs on Thursday 16th of March 2017 11:41:14 PM
Old 03-17-2017
Quote:
Originally Posted by RudiC
How about
Code:
ls /etc/init.d/*was.init | awk '{print TRS "${service_cmd} "$0 " status"; TRS = " && "}' ORS=""

---------- Post updated 03-17-17 at 09:11 AM ---------- Previous update was 03-16-17 at 04:59 PM ----------

Thanks RudiC.

used the suggested and it works fine, But the execution of the variable fails like below,

Code:
[node14 init.d]# export service_cmd=/sbin/service
[node14 init.d]# var1=`cd /etc/init.d/; ls *was.init | awk '!/dmgr/ && !/NodeAgent/ && !/interdependentwas/ {print TRS "${service_cmd} "$0 " status"; TRS = " && "}' ORS=""`
[node14 init.d]# echo $var1
${service_cmd} cmserver_was.init status && ${service_cmd} fmserver_was.init status && ${service_cmd} ihs_was.init status && ${service_cmd} intgserver_was.init status && ${service_cmd} itsmserver_was.init status && ${service_cmd} server2_was.init status && ${service_cmd} sysserver_was.init status
[node14 init.d]# $var1
-bash: ${service_cmd}: command not found
[node14 init.d]#

but the copy paste of the command gives the proper output,

Code:
node14 ~]# ${service_cmd} cmserver_was.init status && ${service_cmd} fmserver_was.init status && ${service_cmd} ihs_was.init status && ${service_cmd} intgserver_was.init status && ${service_cmd} itsmserver_was.init status && ${service_cmd} server2_was.init status && ${service_cmd} sysserver_was.init status
Server - cmserver is running (5330).
Server - fmserver is running (6977).
HTTPServer is running.
Server - intgserver is running (15401).
Server - itsmserver is running (8771).
Server - server2 is running (7679).
Server - sysserver is running (2698).

Can yu pls suggest and guide whats going wrong, and how to achieve this?

Code:
[node14 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.8 (Santiago)

even below one fails to execute completely Smilie

Code:
[node14 ~]# var1=$(cd /etc/init.d/; ls *was.init | awk 'BEGIN{service_cmd="/sbin/service"} !/dmgr/ && !/NodeAgent/ && !/interdependentwas/ {print TRS service_cmd" "$0 " status"; TRS = " && "}' ORS="")
[node14 ~]# echo $var1
/sbin/service cmserver_was.init status && /sbin/service fmserver_was.init status && /sbin/service ihs_was.init status && /sbin/service intgserver_was.init status && /sbin/service itsmserver_was.init status && /sbin/service server2_was.init status && /sbin/service sysserver_was.init status
[node14 ~]# $(echo $var1)
Server - cmserver is running (5330).
[node14 ~]#


Thanks,
Chandana

Last edited by chandana.hs; 03-17-2017 at 01:08 AM.. Reason: added one more code output
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rs and ors in gawk ...????

:D dear members I have a good knowledge of gawk and seem to do quite well with it.. but I have never understood what the use of the rs and ors are for or how they are used.. i am thinking they are for seperating lines and paragraphs but i have absolutely no idea how to make it work, if that is what... (2 Replies)
Discussion started by: moxxx68
2 Replies

2. UNIX for Dummies Questions & Answers

Record too long for awk

I am trying to generate a small report with the help of awk. The contents are present in a file whose last line is very long. I can't shorten this line as its generated after a lot of processing. On reading this file awk says record "starting of line ..." too long record number 30 Now... (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

3. Shell Programming and Scripting

awk: record has too many fields

Hi, I'm trying this command - but get this error. Do you guys have any workaround for this? cat tf|sed 's/{//g'|sed 's/,//g'|awk '{for (i=1;i<=NF;i++) {if ($i == "OPTIME") {k = i + 2; print $i,$k}}}' awk: record `2005 Jul 28 17:35:29...' has too many fields record number 15 This is how... (3 Replies)
Discussion started by: chaandana
3 Replies

4. Shell Programming and Scripting

Trouble getting the next to last record with awk

Hello all, I'm a beginner to shell/ awk script writing, and I'm trying to do something that looks like it shouldn't be (too) hard at all to do, but unfortunately, I can't seem to be able to find the right way to do it with awk. I need to look for the time several processes start & end in a... (5 Replies)
Discussion started by: Muadib
5 Replies

5. UNIX for Dummies Questions & Answers

Awk: print all URL addresses between iframe tags without repeating an already printed URL

Here is what I have so far: find . -name "*php*" -or -name "*htm*" | xargs grep -i iframe | awk -F'"' '/<iframe*/{gsub(/.\*iframe>/,"\"");print $2}' Here is an example content of a PHP or HTM(HTML) file: <iframe src="http://ADDRESS_1/?click=5BBB08\" width=1 height=1... (18 Replies)
Discussion started by: striker4o
18 Replies

6. UNIX for Dummies Questions & Answers

awk: record too long

Hi All , I am getting record too long for the below command . nawk -F\" '{a=a" "$2} END{for(i in a) print i,a }' test|sort|awk '{for(i=1;i<=NF;i++) t=t"\t"$i;if(NF>max)max=NF} END{for(i=1;i<=max;i++)print t }' File test has 850 records ... Please help.. (2 Replies)
Discussion started by: saj
2 Replies

7. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

8. Shell Programming and Scripting

awk RS/ORS error

Hello, I am trying to filter fastq file (in short, every 4 lines to be a record) based on the GC counts (GC-contents) in sequence (i.e. field 2), which is the count % of the G/C chars in the string. The example script is to pick up records with GC contents > 0.6 in the sequence (second field). ... (9 Replies)
Discussion started by: yifangt
9 Replies

9. Shell Programming and Scripting

How to get row data printed in column using awk?

Hi team, I have below sample file. $ cat sample dn: MSISDN=400512345677,dc=msisdn,ou=NPSD,serv=CSPS,ou=servCommonData,dc=stc structuralObjectClass: NphData objectClass: NphData objectClass: MSISDN entryDS: 0 nodeId: 35 createTimestamp: 20170216121047Z modifyTimestamp: 20170216121047Z... (3 Replies)
Discussion started by: shanul karim
3 Replies

10. UNIX for Beginners Questions & Answers

Can someone please explain why we need to set ORS in below awk code?

Question: Write a command to print the fields in a text file in reverse order? awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "\n"}' filename I was thinking it should be (what is the need to set ORS="" ? )- awk 'BEGIN { for(i=NF;i>0;i--) print $i," "; print "\n"}' filename (3 Replies)
Discussion started by: Tanu
3 Replies
All times are GMT -4. The time now is 01:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy