Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse output with bash script and awk

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
0
0
US
My command returns this:

Libsmbios: 0.8.0
System ID: 0x01B2
Service Tag: D*****1
Product Name: PowerEdge 2950
BIOS Version: 2.1.1
Vendor: Dell Inc.
Is Dell: 1


I need to loop through each row and move the value left of the ":" to one variable and the value to the right of the ":" to a second variable.

How?

 
why do you need awk:

Code:
#!/bin/bash

while IFS=":" read f1 f2
do
  echo "$f1"
  echo "$f2"
done < myfile.txt
 
olded
That works if theres a file involved (myfile.txt). But theres no file. The output is coming from a linux command.

Can your snippet be modified top handle that?

-A
 
Try piping your command:

Code:
Linux command|
while IFS=":" read f1 f2
do
  echo "$f1"
  echo "$f2"
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top