I need to do a script in bash programming language. My problem is described bellow:
I have one log file and i need to read it taking some fields separated by comma and save them in a new file.
So, how can i take, for example, the first and third fields of the each line and save them in the new file.
Message was edited by: FilipeMotta
NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
This topic has been locked.
5 replies Latest Post - 2009-01-05T17:28:52Z by senhu
Pinned topic Program an script ( bash )
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2009-01-05T17:28:52Z at 2009-01-05T17:28:52Z by senhu
Re: Program an script ( bash )2008-03-11T13:27:57Z in response to SystemAdminHi,
I did through cut command, but i yet get the wrong information. My original file is described bellow:
I want filter the date, the action and the email, so i put the follow command:
cut -d, -f2,3,4,8,9 file
Ok, the file was filter, but i want the unique result of the email. I tried to use the uniq command but i'm not get the correct result. I tried this command line:
cut -d, -f2,3,4,8,9 file | uniq -f 8
but the result retrieve only one line when it should give two lines. If someone knows how unique result of the email, please, answer it...
Message was edited by: FilipeMottaUpdated on 2008-03-11T13:27:57Z at 2008-03-11T13:27:57Z by SystemAdmin
Re: Program an script ( bash )2008-03-12T16:53:30Z in response to SystemAdminHi,
Before using the uniq command,you have to sort the inputs.So try this one
cut -d, -f2,3,4,8,9 file2.txt | sort -t "," +4 | uniq
-t - for specifying the delimiter
+4 - for sorting based on the fifth field from the input of cut command ie,email
senhu 270001VNM41 PostACCEPTED ANSWER
script in biterscripting2009-01-05T17:28:52Z in response to SystemAdminYou can use the following commands in biterscripting (http://www.biterscripting.com) for more control and more parsability on input lines.
wex "1" # Extract 1st field
wex -e "3" # Extract 3rd field even if it is empty (-e)
wex $n # Extract n'th field (n is an int variable)
lex "1" # Extract first line
lex "l" # Extract last line (in double quotes is the letter l=Ell
lex $k # Extract k'th line
len # Get number of lines
wen # Get number of fields
(I am a scripting trainer.)