Problem in using cut command with pipe as a delimiter while using in a script

There is a text file in my project named as "mom.txt" in which i want to have contents like..................

LSCRM(Application Name):
1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good.| (Here i am using pipe)

MCRM(Another application name)
1: This is MCRM App
2: Secondary app.
3: Good app and so on.| (Using pipe)

AND THE SAME ABOVE MENTIONED FORMAT FOR REST APPLICATION.

Now I have another HTML file called "momcpy.html" which i create in the script mentioned below where i have different text fields/area with their respective name.
Now i want to cut values from mom.text file by using my script file when user inputs in the same format that i have mentioned above for LSCRM Application and replace the cut value in the HTML file in the specific text area assigned to that application(Let us assume the text area name for LSCRM App is "lscrm" and so on for rest application). But in my case, cut command isn't working properly when i am using pipe as delimiter. For LSCRM app, i want to cut values from point 1 to point 4 and replace this cut value in its text area and same for MCRM in its text area. You can see, i have used pipe as delimiter above. Plz help asap, appreciated in advance.

My script is :

#! /bin/bash -x
file='/home/websphe/tomcat/webapps/MOM/mom.txt'
file1='/home/websphe/tomcat/webapps/MOM/web/mom.html'
common_path='/home/websphe/tomcat/webapps/MOM/web/'
cp $file1 $common_path/momcpy.html
if test -s $file
   then
attendees=`cat $file | cut -d '|' -f2`
echo $attendees
lscrm=`cat $file | cut -d '|' -f3`
echo $lscrm
mcrm=`cat $file | cut -d '|' -f4`
echo $mcrm
tlgapi=`cat $file | cut -d '|' -f5`
echo $tlgapi
concerns=`cat $file | cut -d '|' -f6`
echo $concerns
appreciation=`cat $file | cut -d '|' -f7`
echo $appreciation
perl -p -i -e "s#attendees#$attendees#g" $common_path/momcpy.html
perl -p -i -e "s#lscrm#$lscrm#g" $common_path/momcpy.html
perl -p -i -e "#mcrm#$mcrm#g" $common_path/momcpy.html
perl -p -i -e "s#tlgapi#$tlgapi#g" $common_path/momcpy.html
perl -p -i -e "s#concerns#$concerns#g" $common_path/momcpy.html
perl -p -i -e "s#appreciation#$appreciation#g" $common_path/momcpy.html
     echo "`/bin/sh ./mail.sh`"
             rm $file
             rm $common_path/momcpy.html
  else
    echo "Sorry no email sent :("
fi
~

Your script is set up to trace its activity while it is running. If you show us that trace output, we'll have a much better chance of understanding what you're talking about.

You have shown us that you are trying to extract data from seven vertical bar separated fields in your input file, but the sample input file you have shown us never has more than one vertical bar. So, fields 3 through 7 must always be empty.

About all I can say that could be done to solve your problem with what you have shown us would be to rewrite your script to extract data from you input file in a way that matches the format of the data you are processing.

Hi Cragun,

First of all thankyou for your time ! Here i didn't understand what you told that 7 vertical bars. Its like suppose in my text file , i have data that looks like:

LSCRM(Application Name):
1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good.| (Here i am using pipe)

After Point 4 you can see pipe as delimiter. Now if i want to cut this whole lscrm value from text file and replace the cut value in a HTML file in text area by:

****************

lscrm=`cat $file | cut -d '|' -f1`
perl -p -i -e "s#lscrm#$lscrm#g" $common_path/momcpy.html

***************************
I didn't see this value........ "

1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good

" ...........that get cut.

Instead , i see only the first line that is point 1 got cut.i.e. " 1: This is my first application. "

So, plz reply with any command that can help me get the desired value.

Thanks

Please make sure you're using code tags as required in the future!

Almost all *nix text tools work on a per line basis, i.e. on an arbitrary number of characters terminated by a <LF> (\n, 0x0A) char. That's why cut yields the entire file except for any line's pipe char and rest of that line.
My perl is non-existent, but with awk you could get at your desired result like

awk  -F'|' '{print $1}' RS="" file
LSCRM(Application Name):
1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good.

Allow me to comment that your data structure as well as your chosen approach seem somewhat unorthodox and inefficient.

The data that you have in your text file and the commands you are using to extract data from that text file do not seem well suited to what you are trying to do. Please create a file named test.txt that contains the following text:

f1|f2|f3|f4|f5|f6|f7
field 1|field 2|field 3|field 4|field 5|field 6|field 7
3: It was really a good fun in doing so.
4: Really good.| (Here i am using pipe)

After creating that file, what output do you get when you run the command:

cut -d '|' -f2 test.txt

What output do you get when you run the command:

cut -d '|' -s -f2 test.txt

What output do you get when you run the command:

cut -d '|' -f2,4-6 test.txt

After running these commands do you understand what I meant about the 6 vertical bars (AKA pipe symbols)? Do you see that the cut commands in your script are extracting data from 7 pipe symbol delimited fields from lines in the input you feed into it, but only two of those lines contain any pipe symbols?

Have you read the manual page for cut on your system? If not enter the command:

man cut

and look at how it describes the -d , -f , and -s options. I know that you aren't using the -s option in your code, but (with the possible exception of when you are extracting field 1 data) you might want to consider it. Do you understand now what I meant when I said "you are trying to extract data from seven vertical bar separated fields in your input file"?

Hi RudiC,

As u mentioned about the awk command, i tried using it, still i didn't get the desired result.

On running :

awk -F'|' '{print $1}' RS="" input file

My output result is only LSCRM:
But i want LSCRM:

1: This is my first application.
2: Today we did shell scripting automation for this app. 
3: It was really a good fun in doing so. 
4: Really good

.

As this the value user is supposed to give as an input.Any help highly appreciated !

---------- Post updated at 02:03 PM ---------- Previous update was at 01:49 PM ----------

Hi Cragun,

I understood what you tried to explain me about 7 vertical bars.
And i also tried by creating test.txt file and ran the following commands.

But i have an input field as

LSCRM: 
1: This is my first application.
2: Today we did shell scripting automation for this app. 
3: It was really a good fun in doing so. 
4: Really good.

So, to cut All those 4 lines together and store it in a varaible, which command or which delimiter shall i use?

I dont want to have in f1|f2|f3|f4|f5|f6|f7 this format.

It should be

f1
1:
2:
3:
4:    | (Means f1 ends after line 4)
f2
1:
2:
3:   |( f2 ends after line 3)

Thanks

With an input file

cat file
LSCRM(Application Name):
1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good.| (Here i am using pipe)

MCRM(Another application name)
1: This is MCRM App
2: Secondary app.
3: Good app and so on.| (Using pipe)

LSCRM(Application Name):
1: This is my first application.
2: Today we did shell scripting automation for this app.
3: It was really a good fun in doing so.
4: Really good.| (Here i am using pipe)

,

awk -F'|' '{print $2}' RS="" file

delivers

 (Here i am using pipe)

MCRM(Another application name)
1: This is MCRM App
2: Secondary app.
3: Good app and so on.

, so I guess something is wrong with your file / setup. Please give us way more context / background.

I apologize for my earlier post (which has now been deleted). I thought I had posted the following in an earlier post. Since I hadn't, I'll ask the question now.

Is the subject of this thread a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework Questions forum under special homework rules.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.