Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help fixing a file 1

Status
Not open for further replies.

chomps303

MIS
Sep 30, 2003
83
US
I have the following lines in a file. How can I find the
^M in the middle of the line. ie: JOHN^MS HOPKINSAPL . I need to identify this line. BUT all lines end with a ^M.
Is this possible?

Please HELP!!!! and thanks in advance

Brandt

^M
DA123299911C8A 2929
SOMEWHERE XX21738 99945551212 JOHN^MS HOPKINSAPL


^M
EA0 1234876C8A NN0 N Y12349218N 4

N00000002189 6227 AY20040308COLUMBIA 31 OFFICE

 
What do you want do do with the line when you have "identified" it? To delete the ^M, use

/^M.*^M/ {
while ($0 ~ /^M.*^M/) sub(/^M/,"")
print
}


CaKiwi
 
Try something like this:
cM=`echo \015`
sed -e "s!$cM\(..\)!\1!g" </path/to/input > output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 

PHV

I tried your sed line and it seems to find every line since each line has a ^M at the end of the line. I just want to find it if the ^M is NOT at the end of the line.

Thanks

Brandt
 
Code:
BEGIN{cr=sprintf("%c",13)}

{ sub(cr"$", "")
  if (index($0,cr))
  { printf "Found cr in line %d:\n%s\n",
        NR, $0
    sub(cr, "@")
    print "Changed cr to @."
    print
  }
}
 
futurelet

This looks good how do I use this snipit of code?

Thanks

Brandt
 
Sorry, misread the question:
cM=`echo \015`
sed -n "s!$cM\(..\)!\1!p" </path/to/input

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I would put in a file named something like 'find-cr.awk' and run it with:
[tt]awk -f find-cr.awk datafile[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top