|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I have a requirement to convert a file from one format to another. Parent file: Quote:
Quote:
1.) all the lines which begin with "Sample:", should be converted in such a way that entire text after ":" gets converted into all-lower case. 2.) all the lines which begin with "domain:" get stripped off the text mentioned after "@" sign. Please guide. Thanks in advance ![]() |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
One of your needed functions
Code:
$ echo Sample: ABCdefGHiJ | awk '{if($1=="Sample:") print tolower($_)}'
sample: abcdefghij |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi joyeg ,
Thanks for the reply, but unfortunately it did not work ![]() Quote:
![]() |
|
#4
|
||||
|
||||
|
Confused...
Code:
$ cat sample16.txt
Sample: ABCdefgh
domain: when you think abcd@tester.com
domain: abcdefgh@tester2.com
Goods for purchase:234
domain: efgh@anyother.com
Sample: PQRST
Sample: nmjkl
Sample: 123jjkl Mer.
Goods for purchase: No ChaNGE
$ awk '{if($1=="Sample:") {print tolower($_)} else {print}}' <sample16.txt | sed 's/^sample:/Sample:/'
Sample: abcdefgh
domain: when you think abcd@tester.com
domain: abcdefgh@tester2.com
Goods for purchase:234
domain: efgh@anyother.com
Sample: pqrst
Sample: nmjkl
Sample: 123jjkl mer.
Goods for purchase: No ChaNGE |
| The Following User Says Thank You to joeyg For This Useful Post: | ||
dipanchandra (06-15-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks Joeyg !! It works !!! .. For that @ part, just found out a simple-non surgical solution: Code:
$ echo "domain: efgh@anyother.com" | cut -f1 -d"@" domain: efgh Last edited by Scrutinizer; 06-15-2012 at 02:04 PM.. Reason: quote tags to code tags |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Assuming no ':' occurs after the first one ... Code:
$ awk -F: '$1=="Sample"{print $1,tolower($2);next}$1=="domain"&&e=index($2,"@"){print $1,substr($2,1,e-1);next}1' OFS=: input
Sample: abcdefgh
domain: when you think abcd
domain: abcdefgh
Goods for purchase:234
domain: efgh
Sample: pqrst
Sample: nmjkl
Sample: 123jjkl mer.
Goods for purchase: No ChaNGEMuch more general: Code:
#!/usr/bin/awk -f
$1=="Sample:"{s=$0;sub(/^[^:]*:/,"",s);print $1 tolower(s);next}
$1=="domain:"&&e=index($0,"@"){print substr($0,1,e-1);next}
1but really depends how formatted the file is to get specific good answer. =\ Last edited by neutronscott; 06-15-2012 at 02:21 PM.. |
| The Following User Says Thank You to neutronscott For This Useful Post: | ||
dipanchandra (06-16-2012) | ||
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Hi neutronscott....
Seems like some issue ![]() Quote:
Quote:
Last edited by dipanchandra; 06-16-2012 at 08:49 AM.. |
| Sponsored Links | ||
|
![]() |
| Tags |
| case, conversion, text processing |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Conversion from Upper Case to Lower Case Condition based | tsbiju | Shell Programming and Scripting | 12 | 07-08-2011 02:53 PM |
| Extract selective block from XML file | dips_ag | Shell Programming and Scripting | 6 | 01-04-2011 04:29 AM |
| To compare selective file in different folders | gmahesh2k | UNIX for Dummies Questions & Answers | 0 | 05-15-2008 02:03 AM |
| Selective, recursive file diddling! | dinalt | UNIX for Dummies Questions & Answers | 7 | 04-07-2005 06:31 PM |
| lower case to upper case string conversion in shell script | dchalavadi | UNIX for Dummies Questions & Answers | 3 | 05-29-2002 12:07 AM |
|
|