a SED/AWK way to remove everything except...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting a SED/AWK way to remove everything except...
# 1  
Old 03-25-2010
a SED/AWK way to remove everything except...

Hi all,

Code:
I have a logfile which has lines as following:
DOMAIN\username,Deposit,DOMAIN\ServiceAccountName,25/03/2010,00:10,\\SERVER,,,,/Ts=4BAA9BD6,,,10.00,10.03

It's a log of a pcounter print charge system.
I need to only have the first part (domain\username) and the second last (deposited balance) for a other script to make the balance deposits right.
I have a PC_TODAY.LOG which contains 141 lines of above example.

Thanks for the help.

Regards.

Last edited by Franklin52; 03-26-2010 at 04:15 AM.. Reason: Please use code tags!
# 2  
Old 03-25-2010
Code:
$ echo DOMAIN\username,Deposit,DOMAIN\ServiceAccountName,25/03/2010,00:10,\\SERVER,,,,/Ts=4BAA9BD6,,,10.00,10.03 |
> awk -F"," ' { print $1 , $(NF-1) } '
DOMAINusername 10.00

# 3  
Old 03-25-2010
Thanks alot for the quick response anbu23,

As I mentioned, its a logfile with more then one line (141 lines to be exact).

Code:
$ cat PC_TODAY.LOG | awk -F "," ' { print $1 , $(NF-1) } '

Works like a charm!
Thx Smilie

Last edited by Franklin52; 03-26-2010 at 04:32 AM.. Reason: Please use code tags!
# 4  
Old 03-25-2010
Quote:
Originally Posted by necron
Thanks alot for the quick response anbu23,

As I mentioned, its a logfile with more then one line (141 lines to be exact).

$ cat PC_TODAY.LOG | awk -F "," ' { print $1 , $(NF-1) } '

Works like a charm!
Thx Smilie
No cat in the forum. Smilie

Code:
awk -F "," ' { print $1 , $(NF-1) } ' PC_TODAY.LOG

# 5  
Old 03-25-2010
Code:
s="DOMAIN\username,Deposit,DOMAIN\ServiceAccountName,25/03/2010,00:10,\\SERVER,,,,/Ts=4BAA9BD6,,,10.00,10.03"
echo $s | sed 's/\(.[^,]*\).*,\(.[^,]*\),\(.[^,]*\)/\1 \2/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. Shell Programming and Scripting

Want to remove / and character using awk or sed

Below i am trying to remove "/" and "r" from the output, so i need output as: hdiskpower3 hdisk0 hdisk1 #inq | grep 5773 | awk '{print $1}' | sed 's/dev//g' | awk -F"/" '{$1=$1}1' .....................................................//rhdiskpower0 //rhdiskpower1 //rhdiskpower2... (3 Replies)
Discussion started by: aix_admin_007
3 Replies

3. Shell Programming and Scripting

sed awk to remove the , in a string

Dear All, Can anyone help to remove the , bewteen "" in a string by using sed or awk? e.g. input : 1,4,5,"abcdef","we,are,here",4,"help hep" output:1,4,5,"abcdef","wearehere",4,"help hep" Thanks, Mimi (5 Replies)
Discussion started by: mimilaw
5 Replies

4. Shell Programming and Scripting

awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1 Command am using Gives same output as below format: 22B7 10000000c9720873 0 22B7 10000000c95d5d8b 0 22BB 10000000c97843a2 0 22BB 10000000c975adbd 0 Not showing FA ports as required format... (5 Replies)
Discussion started by: aix_admin_007
5 Replies

5. Shell Programming and Scripting

Remove letter from $1 using awk or sed

I have a file: 575G /local/mis/SYBDUMP I want to remove the G, K, M or T so I can use $1 in awk or sed to do math. I want to end up with a file containing: 575 /local/mis/SYBDUMP It should not matter how small or large the numeric numbers are so if 2, 3, 4, or 5 digits etc I want to see... (9 Replies)
Discussion started by: tamvgi
9 Replies

6. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

7. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

8. Shell Programming and Scripting

How to remove lines before and after with awk / sed ?

Hi guys, I need to remove the pattern (ID=180), one line before and four lines after. Thanks. (5 Replies)
Discussion started by: ashimada
5 Replies

9. Shell Programming and Scripting

Remove certain parameters from column using awk or sed

I have a text file Nov 1 LOG_10_000000343.gzip_COMPLETE 2910 server.log.3 Nov 4 LOG_10_000000343.gzip_COMPLETE 2910 server.log.4 Dec 5 LOG_10_000000343.gzip_blah 2910 server.log.5 Jul 6 LOG_10_000000343.gzip_ERROR 2910 server.log.1 I need to convert this to Nov 1 LOG_10_000000343.gzip... (3 Replies)
Discussion started by: gubbu
3 Replies

10. Shell Programming and Scripting

Sed or Awk to remove specific lines

I have searched the forum for this - forgive me if I missed a previous post. I have the following file: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah alter table "informix".esc_acct add constraint (foreign key (fi_id) references "informix".fi ... (5 Replies)
Discussion started by: Shoeless_Mike
5 Replies
Login or Register to Ask a Question