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
Re: Program an script ( bash )2008-03-11T13:27:57ZThis is the accepted answer. This is the accepted answer.Hi,
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:30ZThis is the accepted answer. This is the accepted answer.
- SystemAdmin 110000D4XK
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 Post
script in biterscripting2009-01-05T17:28:52ZThis is the accepted answer. This is the accepted answer.You 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.)