![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read some lines from file!!! | andy2000 | Shell Programming and Scripting | 7 | 03-28-2007 01:55 AM |
| Read lines from file | sagolo | UNIX for Dummies Questions & Answers | 2 | 11-27-2006 12:14 AM |
| how to read lines one by one from a file | bihani4u | UNIX for Dummies Questions & Answers | 5 | 09-28-2006 04:55 PM |
| Need to read a file in reverse | scorreg | Shell Programming and Scripting | 5 | 03-01-2006 09:14 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
How reverse cut or read rows of lines
Hi,
My records are like this BSC403_JAIN03|3153_TropicalFarm_LIMJM1-3_97| BSC403_JAIN03|3410_PantaiAceh_PCEHM1_4_97| BSC406_BMIN02|1433_JomHebohTV3_COW7M1_11_97| I want to extract the value before _97| This command BSC_ID=`echo $DATA | cut -f5 -d"_"` gives me _97|, 4, 11 and by using the command echo $DATA | awk -F_ '{print $(NF-1)}' I get LIMJM1-3, 4, 11. I want to extract 3,4, and 11 only. please help. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
sed 's/.*[-_]\([^-_][^-_]*\)[-_].*/\1/' myFile |
|
#3
|
|||
|
|||
|
try this:
Code:
echo $DATA | awk -F[_-] '{print $(NF-1)}'
|
|
#4
|
|||
|
|||
|
when i use the BSC_ID=`echo $DATA | awk -F[_-] '{print $(NF-1)}`
i get BSC403_JAIN03 BSC403_JAIN03|3153_TropicalFarm_LIMJM1-3_97| BSC403_JAIN03 BSC403_JAIN03|3410_PantaiAceh_PCEHM1_4_97| BSC406_BMIN02 BSC406_BMIN02|1433_JomHebohTV3_COW7M1_11_97| which is incorrect |
|
#5
|
|||
|
|||
|
to more precise the number of underscores are not fixed in my file.
BSC403_JAIN03|3153_TropicalFarm_LIMJM1-3_97| BSC403_JAIN03|3410_PantaiAcehPCEHM1_4_97| BSC406_BMIN02|1433_JomHebohTV3_COW7M1_11_97| so that is the reason why I want to read from reverse and get the value before _97| |
|
#6
|
|||
|
|||
|
can you please explain hoe does ths work???
|
|
#7
|
||||
|
||||
|
Quote:
Code:
echo $DATA | awk -F[_-] '{print $(NF-1)}'
|
||||
| Google The UNIX and Linux Forums |