awk split command to get the desired result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk split command to get the desired result
# 1  
Old 03-06-2015
awk split command to get the desired result

Dear all,
I am using the awk 'split' command to get the particular value.

Code:
FILE=InputFile_009_0.txt               
Temp=$(echo $FILE | awk '{split($FILE, a, "e_"); print a[2]}')

I would like to have the Temp take the value as : _009_0

any suggestions?

Thanks in advance,
emily
# 2  
Old 03-06-2015
Hello emily,

You could try following command and let us know if this helps.
Code:
echo $FILE | awk '{match($0,/\_.*\_/);print substr($0,RSTART,RLENGTH+1)}'

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 03-06-2015
How about:
Code:
filenoext=${FILE%.*}
Temp=${filenoext#InputFile}

--
with awk:
Code:
echo "$FILE" | awk '{split($0, F, /InputFile|\./); print F[2]}'

or
Code:
echo "$FILE" | awk -F 'InputFile|[.]' '{print $2}'


Last edited by Scrutinizer; 03-06-2015 at 09:51 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 03-06-2015
@Emily. What does this have to do with your original question? Please start a new thread for a new topic...
# 5  
Old 03-06-2015
Quote:
Originally Posted by Scrutinizer
@Emily. What does this have to do with your original question? Please start a new thread for a new topic...
Sorry, It has been moved to separate thread.

regards,
emily.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk split and awk calculation in the same command

I am trying to run the awk below. My question is when I split the input, then run anotherawk to perform a calculation using that splitas the input there are no issues. When I try to combine them the output is not correct, is the split not working or did I do it wrong? Thank you :). input ... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

Use bash command on awk field and output the result

Hello, I want to run a field from an awk command through a command in bash. For example my input file is 1,2,3 20,30,40 60,70,80 I want tot run $2 thought the command date +%d/%m/%y -d"01/01/15 + $2 days -1 day" and get the output 1,02/01/15,3 20,30/01/15,40 60,11/03/15,80 ... (2 Replies)
Discussion started by: garethsays
2 Replies

3. Shell Programming and Scripting

awk command gives incorrect result?

Hi All, I am looking to filter out filesystems which are greter than a specific value. I use the command df -h | awk '$4 >=70.00 {print $4,$5}' But this results out as below, which also gives for lower values. 9% /u01 86% /home 8% /u01/data 82% /install 70% /u01/app Looks... (3 Replies)
Discussion started by: jjoy
3 Replies

4. Shell Programming and Scripting

Print if found non-desired result

I have a result like this root@server # grep -rl maldet /etc/cron* /etc/cron.d/maldet_daily /etc/cron.d/malcron /etc/cron.d/malcrondaily /etc/cron.d/malcronweekly What I need is, I need an if/else condition such that, if there is any output other than /etc/cron.d/maldet_daily in the... (8 Replies)
Discussion started by: anil510
8 Replies

5. Shell Programming and Scripting

Want to split awk command

Hi, There is an awk command in script and it is running successfully. I want to split that command in 2 lines. I have tried using '\' but its not working.. Please suggest me the solution. (11 Replies)
Discussion started by: Sanket Dalvi
11 Replies

6. UNIX for Dummies Questions & Answers

Help me in getting the desired result

Hi All, I have input file which is pipe delimited A | 1 B | 2 c | 3I need output of displaying total number of lines in a file as last column. A | 1 | 3-----total number of linesin file. B | 2 | 3 c | 3 | 3 (9 Replies)
Discussion started by: pravinashwin
9 Replies

7. Shell Programming and Scripting

AWK command to cut the desired header columns

Hi Friends, I have a file1 i want to retrieve only the fields which have DEP,CITY,TRANS as headers in other file. Output: I want to give the input as DEP,CITY,TRANS column names to get the output. i used cut command .. but if i have 300 fileds it is more difficult to... (4 Replies)
Discussion started by: i150371485
4 Replies

8. Shell Programming and Scripting

Split a file using awk command.

awk 'FNR == 1 { c = 1 } { print > (f c) } !FNR%n { close(f c); ++c }' n=$files_per_stream f=$input_path/filename_ $input_file $input_file with some records are splitted into files named filename_1,filename_2...etc according to $files_per_stream. Plz help me know how and if anyone has... (7 Replies)
Discussion started by: guptam
7 Replies

9. Shell Programming and Scripting

Awk command to split file name

Hi I have few files with format access.2Nov-12:15AM. These files will be generated daily . I need to write a script so that if today's date is less than 10 then it has to zip the file and rename it to acess.02Nov-12:15AM.gz .please help me in this . Also please help me in splitting the file... (10 Replies)
Discussion started by: mskalyani9
10 Replies

10. Shell Programming and Scripting

assign awk command result to a variable

#!/bin/sh # ## MYSTRING = `awk '/myApp.app/' /Users/$USER/Library/Preferences/loginwindow.plist` if then echo String not found defaults write /Users/$USER/Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -dict-add -string Hide -bool YES -string Path -string... (9 Replies)
Discussion started by: dedmakar
9 Replies
Login or Register to Ask a Question