Computing.Net > Forums > Unix > Unix String Manipulation

Unix String Manipulation

Reply to Message Icon

Original Message
Name: eileen_cc
Date: March 15, 2004 at 02:55:48 Pacific
Subject: Unix String Manipulation
OS: UNIX
CPU/Ram: -
Comment:

Hi,

I am new in UNIX programming. I would like to achive the following tasks. could someone advice me?

1) extract the data from comma separator string and placed into arraylist.
2) for every data in the arraylist, scan the log file to find the last date time timestamp that matches with the content in the arraylist

name1=data1,data2,data3

desired output:
arraylist[1]=data1
arraylist[2]=data2
arraylist[3]=data3

thanks
Eileen

EILEEN CHUA


Report Offensive Message For Removal


Response Number 1
Name: aigles
Date: March 15, 2004 at 07:29:12 Pacific
Reply: (edit)

Assume bash and timestamp in field 1 of log file.


#
# Set array
#
IFS=, arraylist=($name1)

#
# Search log file for elements of array
#
for word in "${array[@]}"
do
   grep "$word" log_file | cut -f1
done

#
# The same thing without loop
#
grep -E "$(IFS='|'; echo "${array[*]})" log_file | cut -f 1

Jean-Pierre.


Report Offensive Follow Up For Removal

Response Number 2
Name: LeHKN
Date: March 26, 2004 at 20:53:35 Pacific
Reply: (edit)

Try reading the UNIX man pages on strtok.
It's great for parsing strings with separators.

RadarSync-We drive you happy!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Unix String Manipulation

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge