Jackie James
Jackie James

Reputation: 853

How can i write a shell script to display the below output?

newtext.csv looks like below :

Record 1
---------
line 1 line 2 Sample Number: 123456789 (line no. 3) | | | | | Time In: 2012-05-29T10:21:06Z (line no. 21) | | | Time Out: 2012-05-29T13:07:46Z (line no. 30) 

Record 2
----------
line 1 line 2 Sample Number: 363214563 (line no. 3) | | | | | Time In: 2012-05-29T10:21:06Z (line no. 21) | | | Time Out: 2012-05-29T13:07:46Z (line no. 30) 

Record 3
---------
line 1 line 2 Sample Number: 987654321 (line no. 3) | | | | | Time In: 2012-05-29T10:21:06Z (line no. 21) | | | Time Out: 2012-05-29T13:07:46Z (line no. 30) 

Assume there are such 100 records in a newtext.csv So, now i need the parameters of the entered i/p string, which is something below

Input
Enter the search String :
123456789

Output

Sample Number is, Sample Number: 123456789 
Connected Time is,Time In: 2012-05-29T10:21:06Z 
Disconnected Time is, Time Out: 2012-05-29T13:07:46Z 

This is what exactly i need. Can you please help me with shell scripting for the above mentioned format ?

Upvotes: 0

Views: 197

Answers (1)

neevek
neevek

Reputation: 12148

OK, the input and the desired output are kinda weird, but it's still not difficult to get what you want, try the following:

var=123456789
awk -v "var=$var" --exec /dev/stdin newtext.csv <<'EOF'
  ($7 == var) {
    printf("Sample Number is, Sample Number: %s\n", $7);
    printf("Connected Time is, Time In: %s\n", $18);
    printf("Disconnected Time is, Time Out: %s\n", $27);
  }
EOF

Upvotes: 1

Related Questions