Computing.Net > Forums > Unix > Unix String Manipulation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix String Manipulation

Reply to Message Icon

Name: eileen_cc
Date: March 15, 2004 at 02:55:48 Pacific
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



Sponsored Link
Ads by Google

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

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.


0

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

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

RadarSync-We drive you happy!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix String Manipulation

String manipulation www.computing.net/answers/unix/string-manipulation/7391.html

Unix strings in scripting www.computing.net/answers/unix/unix-strings-in-scripting/6992.html

search & insert text into a string www.computing.net/answers/unix/search-amp-insert-text-into-a-string/5013.html