Linux command to output from a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux command to output from a string
# 1  
Old 09-13-2012
Linux command to output from a string

Hi All,

I have a file with name
Quote:
"/iis_ft_dev_data1/custsys/publish/goldstd/WCC_CUST_GS_NON_TRAN_CTA_DLY.dat".
Is there a LINUX command that will help me to output the word after the 9th Underscore(_).
ie the output should be DLY in this case.

Can anybody pls help me.

Thanks much in advance,
Freddie
# 2  
Old 09-13-2012
Code:
echo "/iis_ft_dev_data1/custsys/publish/goldstd/WCC_CUST_GS_NON_TRAN_CTA_DLY.dat" | sed -n 's/.*_\(.*\)\.dat/\1/p'

DLY

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 09-13-2012
Code:
echo ' /iis_ft_dev_data1/custsys/publish/goldstd/WCC_CUST_GS_NON_TRAN_CTA_DLY.dat' | awk -F'[_.]' '{print $(NF-1)}'

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 09-13-2012
Thanks @vgersh99 & @in2nix4life, both worked fineSmilie

Wondering what we should do to get the last 2 words(before the .) in the output,

ie CTA_DLY

i tried modifying the same commands, but with no luck

Thanks again.
Freddie
# 5  
Old 09-13-2012
Code:
awk -F'[_.]' '{print $(NF-2), $(NF-1)}' OFS=_

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Interpreting Linux's free command output

I have two questions on Linux's free command. Below, I have provided output from my home laptop (fedora 26 ) which has 16GB Physical RAM and a production server (RHEL 7.4) which has 24GB RAM. Question1. What exactly does the buffer/cache column say in free command's output ? buffer/cache is... (9 Replies)
Discussion started by: omega3
9 Replies

2. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

3. Shell Programming and Scripting

Different output for awk command on Linux & HP-UX

I am using an awk command to extract a particular portion of a string. Below is the command and its output on a Linux system: oracle@host1:/tmp (/home/oracle) $uname -a Linux host1 2.6.32-279.39.1.el6.x86_64 #1 SMP Fri Nov 15 05:38:26 EST 2013 x86_64 x86_64 x86_64 GNU/Linux ... (7 Replies)
Discussion started by: veeresh_15
7 Replies

4. Shell Programming and Scripting

Want to terminate command execution when string found in the command output

Hi Experts, I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task. I am running below command to snmpwalk the router.. snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Discussion started by: Hanumant.madane
19 Replies

5. UNIX for Dummies Questions & Answers

LINUX - How to remove the final delimiter from a command output

Hi All, I am trying to list the various dates for which the file is available in a directory using the command below, (& subsequently pass the command output to a loop) Command : ls dir|grep 'filename'|cut -d '_' -f1|cut -c1-8|tr '\n' ',' However, it is giving me an extra comma... (6 Replies)
Discussion started by: dsfreddie
6 Replies

6. Shell Programming and Scripting

Grep command showing wrong output in Linux

Hi All I am trying to run a script in linux wherein i have a command like this grep ^prmAttunityUser= djpHewr2XFMAttunitySetup_ae1_tmp djpHewr2XFMAttunitySetup_ae1_tmp is a temporary file in which the user value is stored but this command in the script returns me balnk value whereas it has a... (4 Replies)
Discussion started by: vee_789
4 Replies

7. UNIX for Dummies Questions & Answers

linux sort command produces strange output

cat a .a ba .b bb .c bc sort a .a .b ba bb bc .c NOTE: .a and .b appears before ba and bb, where as .c appears after bc. In general (3 Replies)
Discussion started by: ajb
3 Replies

8. Shell Programming and Scripting

Command output string manipulation possible in one line?

This has been bothering me for 3 days. $> hostname cepsun64amd And I just want "cepsun", I would normally do h=`hostname`; ${h%%64*} But I am looking for a one-liner just for my own knowledge, because if there is a way to do this, I should know it by now. Anyway, so is this... (2 Replies)
Discussion started by: Ryan.
2 Replies

9. Shell Programming and Scripting

grep only a string on command output

How can I grep exactly a string that has .,/ characters using grep? Example: I want to grep ONLY string1 and not string1.more or string1.more.evenmore #lsauth ALL|grep 'string1' All output: string1 <--- This is the only I want. string1.more string1.evenmore. more.string1... (4 Replies)
Discussion started by: iga3725
4 Replies

10. Programming

How to Run a Linux Command and Redirect its output to a socket in C

I have a Linux socket server program. I need to run the commands sent by the client and return the output to client. Is there a quicker way? I tried with ptr=popen(command, "r"); and then fgets(buf, size,ptr); write buf to socket fgets hangs for me. Now, I would like to know if I can... (3 Replies)
Discussion started by: rajeshomallur
3 Replies
Login or Register to Ask a Question