I have following content in the file
CancelPolicyMultiLingual3=U|PC3|EN
RestaurantInfoCode1=U|restID1|1
.....
I am trying to use following matching extression
\|([^$]+)
to get this
PC3|EN
restID1|1
Obviously it does not work.
Any ideas?
I have following content in the file
CancelPolicyMultiLingual3=U|PC3|EN
RestaurantInfoCode1=U|restID1|1
.....
I am trying to use following matching extression
\|([^$]+)
to get this
PC3|EN
restID1|1
Obviously it does not work.
Any ideas?
Here's one way.....
awk -F "|" '{print $2"|"$3}' test.txt
Kent
Try this:
$
$ echo "CancelPolicyMultiLingual3=U|PC3|EN
> RestaurantInfoCode1=U|restID1|1" | sed 's=[^|]*\(|.*\)=\1='
|PC3|EN
|restID1|1
$
Here's another....
$ grep -o \|.*\|.* test.txt
One more..... The grep one wasn't quite what you were looking for.
$ perl -nle 'while(m/\|(.*)/g){print "$1"}' test.txt
Kent
Alternative in Python. No regular expression
#!/usr/bin/python
for line in open("file.txt"):
print '|'.join(line.strip().split("|")[-2:])
cut -d"|" -f2,3 file
Actually, I should have been more specific.
The lines look like this
CancelPolicyMultiLingual3=U|PC3|EN
RestaurantInfoCode1=U|restID1|1
but they also can look like this
Award1=U|OTA
HotelFact2=U|fact02
and what I need is to ignore all pipes following the first one. Threat them as another character, so I can get this
PC3|EN
restID1|1
OTA
fact02
Thank you in advance
Try using the "cut" command:
cut -d"|" -f 2- filename
thank you,
it works.
I am still wondering if it is possible to do using regular expressions
If you don't mind my asking -- why? If "cut" works, why reinvent the wheel with a complex regex?
Sure,
the reason is I am using three different regular expression to handle each line.
For instance, following lines
...
GuestRoomInfoMultiLingual1=U|3|EN
Phone2=U|1|4
...
I am dividing into three buckets separated by '^'
GuestRoomInfoMultiLingual^U^3|EN
Phone2^U^1|4
For the first two fileds I am using regular expressions. I was hoping to do the same for the third bucket
sed 's/[^|]*|\(.*\)$/\1/' FILE
try this.
cat <filename>|cut -d "=" -f2|cut -d "|" -f2
if u want in script just parse the file name and do ths operation. it should work.please use the easy one. dont go for some expressions which will be difficult..
just use the simplest execution method..