need to retrieve data between the first occurance of "_" and the extension.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to retrieve data between the first occurance of "_" and the extension.
# 1  
Old 05-13-2009
need to retrieve data between the first occurance of "_" and the extension.

hi all,

i have a file that contains the following kind of data

codeexpert_package_module1.html
codeexpert_package_module2.html
codeexpert_package_module3_revision2.html
and it goes on ..

i need to get the following data from it
package_module1
package_module2

i know basename command can be used to remove ".html" part but how to cut the data till the first occurance of the "_".
# 2  
Old 05-13-2009
Try this:

Code:
 
cat file_name | while read line
do
  echo ${line} | cut -d '_' -f2,3 | cut -d '.' -f1 >> /tmp/test.txt
done

cat tmp/test.txt

HTH,Smilie

Regards,

Praveen
# 3  
Old 05-13-2009
Code:
 
echo "codeexpert_package_module3_revision2.html" | awk -F"." '{print $1}' | awk -F"_" '{  print $2"_"$3 }'

# 4  
Old 05-13-2009
Code:
echo 'codeexpert_package_module3_revision2.html' | sed 's/^[^_][^_]*_\(.*\)[.][^.][^.]*$/\1/'

# 5  
Old 05-13-2009

Code:
awk -F '[_.]' '{print $(NF-1)}' "$FILE"

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

How to retrieve "case "statement return value ?

How do we retrieve case statement return value at point indicated in the attached snippet case "$FUN" in 1\ *) do_change_pass ;; 2\ *) do_network_menu ;; 3\ *) do_boot_menu ;; 4\ *) do_internationalisation_menu ;; 5\ *) do_ssh... (6 Replies)
Discussion started by: annacreek
6 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

5. Homework & Coursework Questions

how to change this looking for mimetype "text/plain" instead of extension *.txt?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Create a Shell script that looks for all text files in your home directory (including subdirectories). List... (3 Replies)
Discussion started by: rollinator
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Retrieve RAM memory size from "top" command output

Hi, I am trying to get the system RAM size from "top" command's output by the following but it is not working. top | sed "s/^Mem.**\(*\), *//" (10 Replies)
Discussion started by: royalibrahim
10 Replies

8. Shell Programming and Scripting

Count the Consecutive Occurance of "X" in awk

Hi All, I have a data as follow: 0 0 0 X X 0 X X X 0 X 0 0 X 0 0 (16 Replies)
Discussion started by: nica
16 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question