Question on awk/sed/regex


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question on awk/sed/regex
# 1  
Old 09-19-2012
Question on awk/sed/regex

I plan to do something like this in awk that's embedded in a shell script.

I have extracted a text file using awk and the output is
before example:
Code:
<USDOLLARS|xxx>

I want to use get rid of the starting "<" and anything after the pipe "|"
after example:
Code:
USDOLLARS

How do I do that??
I started out with
Code:
echo <USDOLLARS|xxx> | sed 's/^<//g'

And that's not even working yet
Any solution using sed or some kinda substr that works with awk is welcome!

Any help is appreciated?!Smilie

Last edited by Franklin52; 09-20-2012 at 04:41 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 09-19-2012
Code:
 
echo "USDOLLARS|xxx>" | sed 's/^<//; /|/s/|.*/|/g'


Last edited by fpmurphy; 09-19-2012 at 10:18 PM..
# 3  
Old 09-19-2012
Hi Thank you so much
but this INCLUDES the | at the end
how do i exclude the | as well?
# 4  
Old 09-19-2012
Code:
 
echo "USDOLLARS|xxx>" | sed 's/^<//; s/|.*//g'

# 5  
Old 09-19-2012
and also, when I put this on command line or part of shell script ->works
when i insert it as part of awk program -> syntax error complained

I am fighting this issue alot as i'm relatively new to linux.
# 6  
Old 09-19-2012
Please post what Operating System and version you have and what Shell you are using. Just "Linux" is not enough. Just "syntax error" is not enough.
Please post the actual script, how you ran the script, and what output was produced complete with any error messages verbatim.
Why? Because there are variations in the implementation of sed and awk.
# 7  
Old 09-19-2012
question con't

Code:
awk -F, -v COUNT=$count '
(NR >= 2){
  for(i=1; i<=NF; i++)
  {
        print i
        if ($i ~/^</)
        {
          print $i
          echo "USDOLLARS|xxx>" | sed 's/^<//; s/|.*//g'
          break
        }
  }
}  ' $filename

The code fails here in the awk embedded in the Shell script
Code:
echo "USDOLLARS|xxx>" | sed 's/^<//; s/|.*//g'

I'm on Red Hat Linux Server 5.8

Last edited by Corona688; 09-19-2012 at 07:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

REGEX help required and some sed/awk help as well

Hi guys, I am coding a bash script that makes use of php scripts to pull URL's from a website. These url links will have numbers in them like 0.2.3 I want to make a regex that will yield me such numbers if I use a command like preg_grep. Question1: I need a regex that will tell my preg_grep... (2 Replies)
Discussion started by: mojoman
2 Replies

3. Shell Programming and Scripting

To print lines between 2 timestamps using awk|sed and regex

Hi, I am using the following code to fetch lines that are generated in last 1 hr . Hence, I am using date function to calculate -last 1 hr & the current hr and then somehow use awk (or sed-if someone could guide me better) with some regex pattern. dt_1=`date +%h" "%d", "%Y\ %l -d "1 hour... (10 Replies)
Discussion started by: sarah-alikhan31
10 Replies

4. Shell Programming and Scripting

regex, awk, grep question "how to"

I've been working on this for 2 days and I'm not getting far. It is time to turn to you guys. With the data below, I am trying to create a file that looks like this: I'd like to use some form of egrep I think. AY#box#P04prod_to_contingency s AY#cmd#P04dump_cont_db s AY#cmd#P04get_on_ice_job s... (2 Replies)
Discussion started by: rawbi01
2 Replies

5. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

6. Shell Programming and Scripting

Selecting a part of the text (regex pattern, awk, sed)

Hello, let's start by giving you guys a few examples of the text: "READ /TEXT123/ABC123" "READ /TEXT123/ABC123/" "READ TEXT123/ABC123" "READ TEXT123/ABC123/" "READ TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123/" TEXT and ABC can be and I... (5 Replies)
Discussion started by: TehOne
5 Replies

7. Shell Programming and Scripting

sed to awk (regex pattern) how?

Hello, I am trying to covert a for statement into a single awk script and I've got everything but one part. I also need to execute an external script when "not found", how can I do that ? for TXT in `find debugme -name "*.txt"` ;do FPATH=`echo $TXT | sed 's/\(.*\)\/\(.*\)/\1/'` how... (7 Replies)
Discussion started by: TehOne
7 Replies

8. Shell Programming and Scripting

sed and awk question

hello, I have this in a file server_name=DB1 hostname=db1 I want to change hostname value to `hostname`. Any idea? and server_name value to toUPPER (`hostname`). Any idea? thanks (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

9. Shell Programming and Scripting

Awk Sed question

i have to search direcotry with a Min or Max size and but with a standard find.... it gives me the size of the i-node of the directory. A friend told me to use awk/sed command to search directories. he also gave me this command: find -type d -exec du '{}' \; | awk -v sz=10 '{if... (0 Replies)
Discussion started by: AkiraSama
0 Replies

10. Shell Programming and Scripting

sed, grep, awk, regex -- extracting a matched substring from a file/string

Ok, I'm stumped and can't seem to find relevant info. (I'm not even sure, I might have asked something similar before.): I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies
Login or Register to Ask a Question