Using sed to translate dos line ends to unix line ends.

Here is my first attempt at translation. I read in the sed man page how \ acts differently, but I see references to \r etc.
I have a text file. I do not know if it has \r\n or \r as line ends.
so I want to
change \r\n to \n
then change \r to \n
Thus I end up with unix line ends.
mac $ echo -ne  "1\r\n2\r\n" | sed "/\r\n/\n/g"
sed: 1: "/\r\n/\n/g": invalid command code \
mac $ 
I left out the Mac conversion of \r to \n.
I did a google search looking for the conversion. Lots of attempts at conversion. Lots of people eliminated the \r, that wasn't my idea. I moved to Perl after giving up on sed. Thanks everyone who read & responded to my previous Perl post.
Robert

Cole Tierney wrote:
Sed on linux will honor carriage returns entered as
. BSD sed does not appear to. I've confirmed this on Mac OS 10.3.9 and 10.4.11. On those systems you need to enter a carriage return as a literal using control-v control-m. The carriage return is then displayed as ^M. This can be confusing in forums since people will try to enter it as it is displayed (shift-^ shift-m).
I was unfamiliar with this method of escaping. I saw references to this in my Google search. I am using the commands in an
Applescript, so I didn't know how to enter.
http://discussions.apple.com/edit!default.jspa?messageID=12681001
My work around is to let bash deal with the carriage return using $'
'. The trade off is you then have to look at a lot of single quotes. I find it easier to think of it in a couple steps. To expose the $'
' to bash you first split the sed with a couple single quotes at the point where you want the carriage return to appear.
sed 's///' <- initial
sed 's/''//' <- split
sed 's/'$'
''//' <- insert
</div>
I didn't know about this use of $.
If were dropping down to bash, then what is the deal with this:
mac $ echo -ne  "1
2
" | sed  's/'"
"'//' | hexdump
0000000 310d 0a32 0d0a                         
0000006
I thought double quotes escaped things.
The input for your second example has a line with more than one carriage return. My sed only deletes one carriage return per line. Another option is to anchore the match at the end:
sed 's/'$'
''$//'
I saw the linux version of this, but didn't see the trick of the $ forcing line end and the linux version didn't work for me on Tiger.
This ends my quest for a tiger version of sed.
(( At least for DOS, I think I'll forget the classic version of Mac OS. ))
Thanks.
Robert

Similar Messages

  • Foreign Currency Translation at Year End - How SAP Works for P&L items?

    Hi All,
    I wanted to know "How SAP works on Foreign Currency Translation at year end" from Local Currency to Group Currency for P&L Items.
    I know how SAP works for Balance sheet items but am really confused with when the translation was done for P&L Items.
    Configuration:
    We are on ECC 6.0 . Local Currency is CAD and we have 2nd Local Currency as "USD - Group Curr".
    We have set up Valuation Method - 4
    We have set up Valuation Area - 40
    For Account Determination for Currency Translation, GL accounts (Loss, Gain and B/S Adj)  were setup for the combination of Chart of Accounts, Val Area and Fin Stmt Ver.
    Sales Account Balance
    CAD (LC)        USD (2nd LC)       
    1000                   920                        
    Using tcode "FAGL_FC_TRANS", we translated our P&L items.
    Local Currency is CAD and Group Currency is USD.
    CAD 1000 and USD 920 are cumulative balances over a period of time.
    Since at the end of year CAD became stronger, exchange rate is 1.11 as an example
    Sales Account Balance
    CAD (LC)        USD (2nd LC)        Translated Value in USD
    1000                   920                        900
    System passed the following entry in USD:
    Debit Balance Sheet Adj A/c 20
    Credit Translation Gain / Loss A/c 20
    Here are the questions:
    1. How does over all translation work? - Should we get any Gain / Loss and have an effect on P&L when all accounts (P&L, B/S) are translated?
    2. How can there be a gain entry when USD value has really fallen from 920 to 900 in the current case.
    Thanks for your time.
    Vijay

    Hi,
    I had this issue too.  The entry was just opposite to what it should be.  I just flipped the accounts in table FAGL_T030TR.
    Example: 410000 is sales account which normally should have a credit balance.  Here are some entries that were posted to sales in 03/2009 and I am running FAGL_FC_TRANS at the end of the month.
    March 1, 2009 Cr. Sales CAD 1000- USD 900-
    March 2, 2009 Cr. Sales CAD  500- USD 480-
    During FC translation transaction, system takes the balance in the account for the period (if you execute it with 'Val. period balance only' checkbox checked) and not the cumulative balance.  SAP recommends translating period balance only (and not cumulative balance) for P&L accounts.  It sees a balance in LC (this again depends on the config. you have in OB22 - whether the indicator is 1 (TC as source currency) or 2 (LC as source currency for translation)) which is 1500, converts that at month end rate.  After conversion, lets say the balance is 1400-.
    In this case, we expect a credit entry on sales account
    March 31, 2009 Cr. Sales CAD 0  USD 20-
    But system was just posting the opposite.  I then flipped the accounts in FC translation configuration.  I know it is misleading.  In that configuration, system says balance sheet adjustment account, but what you should actually give there is your gain/loss account.  Our gain/loss a/c. falls in the same GL account range as the main account.  For example, for 410000, it is 410999 and for 510000, it is 510999.  We report accounts 410000 to 410999 in the same node in the FSV.
    Pl. feel free to ask further questions about this.  Pl. test in your system and correct me if my above reply is wrong.
    Cheers!

  • How to use sed on a literal string containing regex meta characters?

    I want to delete the lines from a file which match an arbitrary literal string.
    The string is contained in a variable, and may itself contain various regex meta characters such as [,],^,$,|, etc
    So, my problem is that sed wants to interpret these meta characters itself. For example:
    x='abc[xyz$'
    sed -i "/$x/d" file
    produces a sed error about the unmatched [, and no doubt it wants to interpret the $ too.
    (Of course, I could try and change the string $x so that every possible regex meta character was escaped with a \, but that seems immensely cumbersome. Also, can't see a way of using single or double quotes cleverly.)
    Sorry if I am being thick about this, but any ideas or alternative methods would be most welcome!

    frostschutz wrote:
    With sed, you have to escape meta characters indivudually. That's just how it works. Of course you could do the escaping using sed as well, by replacing all meta characters (including \ and /) with \character.
    If you want to match strings literally, use a different tool. Or do it in Bash.
    while read line
    do
    [ "$line" != "$x" ] && echo "$line"
    done < file
    In Perl/PCRE instead of escaping indivudually there is \Q...\E but sed does not understand that, and \Q\E does not solve all problems either, if there is a \E in the $x you have to escape it with \E\\E\Q or something like it.
    Thank you for your swift reply. Looks like sed can't be much of a friend in these circumstances!
    Probably will have to go with the Bash file handling method.
    Oh well ...

  • JDev specifying SQLJ translator command line options

    Hi,
    I have come across the problem of SQLJ connections caching up to 5 sql commands and so leaving any related cursors open. This is happening mainly for statments where I have executed a SELECT ... INTO ... Any sqlj with iterators, I have closed the iterators so they do get removed and their cursors closed.
    I have found that caching can be switched off via the SQLJ translator command line option -P-Cstmtcache=0.
    How can I specify this command line option within my JDeveloper project settings? I don't want to have to build my project from the command line explicitly as this will complicate the Release Software Build procedure.
    Can anyone help me, please?
    Thanks a lot.

    Can anyone offer any words of wisdom on this? We are currently using JDeveloper 3.1 (Build 681)

  • Mail saving text attachments with DOS line endings

    dear all,
    i just noticed that Mail saves text attachments with DOS line endings (CR+LF), even if the original contains UNIX line endings (LF). how can i disable this behaviour?

    Using Automator, one can make a Desktop application that simulates dos2unix.
    The Automator application shown here, will prompt the user to choose one or multiple (using command key) text files, and will then use Perl to process each file in-place, replacing the carriage return-line feed pairs with just a line feed. I tested this on a folder of text files where each file had more than 1 CRLF pair. Afterwards, there were only LF. The last thing this application does is slide out an OS X notification with processing status and number of files affected. I borrowed, and adapted the Perl block from Stack Overflow.

  • Sedname - Batch rename files using sed

    Renaming files using sed is nothing new, but this script makes the process a little more friendly and adds a few features, including insertion of sequential numbers and a simulation mode.  The output of any find command can also be piped through sedname.
    sedname version 1.0.0
    Batch-renames files using a sed script
    Usage: sedname [OPTIONS] SEDSCRIPT FILE ...
    Usage: find [...] | sedname [OPTIONS] SEDSCRIPT
    Example: sedname 's/\(.*\)\.jpg/\1.jpeg/' *.jpg
    Example: find /mypics | sedname 's/\(.*\)\.jpg/\1.jpeg/'
    OPTIONS:
    --sim simulate only
    --dir rename directories too
    Use #D to insert a number with D digits forming a unique filename
    Example: sedname 's/thisname.*/thatname#3/' *
    ( changes thisname* to thatname001, thatname002, ... )
    Use #0 in replacement name to insert a number if needed
    Example: sedname 's/thisname.*/thatname#0/' *
    ( changes thisname* to thatname, thatname1, thatname2, ... )
    http://igurublog.wordpress.com/download … t-sedname/
    http://aur.archlinux.org/packages.php?ID=37707

    What does it have over zsh's zmv:
    # Remove illegal characters in a fat32 file system. Illegal characters are
    # / : ; * ? " < > |
    # NOTE: ``-Q'' and (D) is to include hidden files.
    $ unwanted='[:;*?\"<>|]'
    $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'
    # Changing part of a filename (i. e. "file-hell.name" -> "file-heaven.name")
    $ zmv '(*)hell(*)' '${1}heaven${2}'
    # or
    $ zmv '*' '$f:s/hell/heaven/'
    # remove round bracket within filenames
    # i. e. foo-(bar).avi -> foo-bar.avi
    $ zmv '*' '${f//[()]/}'
    # serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)
    $ ls *
    1.c asd.foo bla.foo fnord.foo foo.fnord foo.foo
    $ c=1 zmv '*.foo' '$((c++)).foo'
    $ ls *
    1.c 1.foo 2.foo 3.foo 4.foo foo.fnord
    # Rename "file.with.many.dots.txt" by substituting dots (exept for the last
    # one!) with a space
    $ touch {1..20}-file.with.many.dots.txt
    $ zmv '(*.*)(.*)' '${1//./ }$2'
    # Remove the first 4 chars from a filename
    $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
    # Rename names of all files under the current Dir to lower case, but keep
    # dirnames as-is.
    $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
    # replace all 4th character, which is "1", with "2" and so on
    $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'
    # Remove the first 15 characters from a string
    $ touch 111111111111111{a-z}
    $ zmv '*' '$f[16,-1]'
    # Replace spaces (any number of them) with a single dash in file names
    $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'
    # or - with Bash
    $ find . -depth -name '* *' -exec bash -c '
    > shopt -s extglob
    > file=$1
    > dir=${file%/*}
    > name=${file##*/}
    > newname=${name//*([ -]) *([ -])/-}
    > mv -i -- "$file" "$Dir/$newname"' {} {} \;
    # Clean up file names and remove special characters
    $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
    # Add *.py to a bunch of python scripts in a directory (some of them end
    # in *.py and give them all a proper extension
    $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
    # lowercase all extensions (i. e. *.JPG) incl. subfolders
    $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
    # Or - without Zsh
    $ find Dir -name '*.[jJ][pP][gG]' -print | while read f
    > do
    > case $f in
    > *.jpg) ;
    > *) mv "$f" "${f%.*}.jpg" ;
    > esac
    > done
    # remove leading zeros from file extension
    $ ls
    filename.001 filename.003 filename.005 filename.007 filename.009
    filename.002 filename.004 filename.006 filename.008 filename.010
    $ zmv '(filename.)0##(?*)' '$1$2'
    $ ls
    filename.1 filename.10 filename.2 filename.3 filename.4 filename.5 ..
    # renumber files.
    $ ls *
    foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
    $ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
    $ ls *
    foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
    # adding leading zeros to a filename (1.jpg -> 001.jpg, ..
    $ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
    # See above, but now only files with a filename >= 30 chars
    $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'
    # Replace spaces in filenames with a underline
    $ zmv '* *' '$f:gs/ /_'
    # Change the suffix from *.sh to *.pl
    $ zmv -W '*.sh' '*.pl'
    # Add a "".txt" extension to all the files within ${HOME}
    # ``-.'' is to only rename regular files or symlinks to regular files,
    # ``D'' is to also rename hidden files (dotfiles))
    $ zmv -Q '/home/**/*(D-.)' '$f.txt'
    # Or to only rename files that don't have an extension:
    $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
    # Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
    $ chars='[][?=+<>;",*-]'
    $ zmv '(**/)(*)' '$1${2//$~chars/%}'
    # Removing single quote from filenames (recursively)
    $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
    # When a new file arrives (named file.txt) rename all files in order to
    # get (e. g. file119.txt becomes file120.txt, file118.txt becomes
    # file119.txt and so on ending with file.txt becoming file1.txt
    $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'
    # lowercase/uppercase all files/directories
    $ zmv '(*)' '${(L)1}' # lowercase
    $ zmv '(*)' '${(U)1}' # uppercase
    # Remove the suffix *.c from all C-Files
    $ zmv '(*).c' '$1'
    # Uppercase only the first letter of all *.mp3 - files
    $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
    # Copy the target `README' in same directory as each `Makefile'
    $ zmv -C '(**/)Makefile' '${1}README'
    # Removing single quote from filenames (recursively)
    $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
    # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
    $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
    $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively
    (from zsh-lovers)
    Edit: tried it now, and had to remove this silly block to make it let me use alternate delimiters:
    if [ "${sedscript:0:2}" != "s/" ]; then
    echo "Invalid sed script: $sedscript" > /dev/stderr
    exit 1
    fi
    Last edited by JohannesSM64 (2010-05-31 15:29:44)

  • Using Sed to Patch when building AURs

    Im all very new to arch and sed and while im learning fast my understanding of SED isnt good.
    how would i use some sed lines if i wanted to patch something?
    Im sure there's another post about this somewhere but i either cant find it or dont understand it.
    an example i was using to try to teach myself was the unofficial patch to fix the firefox-kde-opensuse AUR.
    so far ive sort of figured out how to use sed to edit text files but how to apply that to the AUR has me stumped.
    Last edited by MeiMei (2012-04-16 17:15:52)

    Oh, thank you. Would it go in the 1st, 2nd, or 3rd place ive listed in that code or somewhere else?
    build() {
    HERE?(1)
    cd "${srcdir}/mozilla-release"
    HERE?(2)
    patch -Np1 -i "${srcdir}/mozilla-firefox-1.0-lang.patch"
    patch -Np1 -i "${srcdir}/firefox-install-dir.patch"
    HERE?(3)
    Edit: Actually perhaps thats something the wiki can help with.
    Last edited by MeiMei (2012-04-16 17:26:21)

  • My mac book air can't start installation, because i use windows installation in DOS to make partion, now no mac os on it. How to get back the mac os? i have a window based iso image from a friend, because in my country there is no Apple service.

    my mac book air can't start installation, because i use windows installation in DOS to make partion, now no mac os on it. How to get back the mac os? i have a window based iso image from a friend, because in my country there is no Apple service.

    It sounds like you destroyed your boot partition and the recovery partition.  Depending on it's age, your MacBook Air might be able to do a net boot.  Plug and ethernet connection into it and attempt to boot.  If it has the right firmware, it will find a net boot configuration on the net and boot that.  Then it will give you a Recovery Partition like display and allow you to reinstall the OS X version that came with it.... assuming that it was Lion or ML.  If your computer came with Snow Leopard, then even the net boot won't work. 
    At that point you need a bootable USB Key, or an external DVD drive AND a Snow Leopard installation DVD. 
    An Apple Store, if there is one nearby, MAY be able to get you going again.  However, whatever is on the SSD now will be toast too.

  • Using cfexecute to execute dos command in windows.

    Hi!
    Well i have a requirement where i need to check status of
    particular service in windows from time to time.
    I inferred that we can use cfexecute for this. Well i tried
    to use the same but i was not successful in achieving the desired
    result.
    The following is the code i have written for the above
    purpose.
    <cfexecute name="sc query Internet Information Services"
    arguments="y"
    outputfile="d:\Temp\Output.txt"
    timeout="90" />
    I get the following message:
    oldfusion.tagext.lang.ExecuteTag$TimeoutException: Timeout
    period expired without completion of sc query Internet Information
    Services
    at
    coldfusion.tagext.lang.ExecuteTag.doStartTag(ExecuteTag.java:170)
    at
    cfserverchecking2ecfm748178803.runPage(D:\Test\serverchecking.cfm:3)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
    at
    coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
    well i have tried using different timeout periods but it dint
    work for me.i have gone crazy with it.
    Please advice on this.
    Many thanks.

    In addition to Mr Black's suggestions, take a look at these
    two entries about using cfexecute on Ben Forta's blog
    http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Util ities
    http://www.forta.com/blog/index.cfm/2006/9/11/A-Couple-Of-CFEXECUTE-Gotchas

  • A have new problem that has appeared in my Mac Mail.  When I type a frequently used email into the 'To: line' it populates the correct name but with 8 different email addresses not associated with that name.

    A have new problem that has appeared in my Mac Mail.  When I type a frequently used email into the 'To: line' it populates the correct name but with 8 different email addresses not associated with that name.  I have gone to the window pop-down to 'previous recipients' and deleted that addressee as well as all the email addresses it is assigning to that name.  I have also deleted the account entirely from my address book.  I have have run repair permissions and also full defrag in iDefrag.  Still the problem persists.  Any suggestions?

    Hello CarolineLongEaton,
    I noticed you posted this problem quite a while ago and wondered if you managed to have it fixed in an alternative way then posting here. It is too bad no one has posted a solution here. I have a similar problem and if you have had yours solved since this occurance how you accomplished it may help me with mine. I am interested to know what you have done about yours.
    If you are interested in comparing the problems to see if your solution (if you have found one) might help me also then here is the link to the discussion.
    https://discussions.apple.com/thread/6116927
    If your problem has not been solved then I will comment here again if/when my issue is resolved as it may help you too. My hope here is that we may help each other. To quote you "all ideas gratefuly recieved". I hope your problem was resolved, ernestly for your sake and selfishly for mine also. I wish you and yours a great day!
    dofromon

  • Compare two pdf files using adobe acrobat through command line

    Does anyone know how to compare two pdf files using adobe acrobat through command line. I want to do this via command line because we want to compare hundreds of file every day through some automated windows tasks.
    If command line option is not available in acrobat, then is it feasible to make use of acrobat javascript API to do this task?
    Any kind of help will be greatly.

    Command-line: Not possible.
    JavaScript: Possible, but very limited. Basically the only thing you can do is simulate clicking the Compare Documents button. The rest has to be done manually.
    However, it *might* be possible to automate this process a bit more using a plugin. Ask over at the Acrobat SDK forum for more information...

  • How to use Bespoke transaction in SRM Front end.

    Hi All,
    I am having a transaction ZPO_REPORT, I want to use this transaction in SRM Front End.
    How can I do it?
    Please advice.
    Regards.
    Pras

    hi pras,
       sorry to ask once again. as per my understand from your questions.
       execute ur report program by SAP-GUI mode???
    thank you,
    Regards,
    John.

  • I need help from chile and use a language translator to write and not turn my iphone4

    I need help from chile and use a language translator to write and not turn my iphone4

    http://support.apple.com/kb/TS3281       
    Not turn on

  • Output type is used for sending / printing "schedule lines" against sch agr

    hi
    which output type is used for sending / printing "schedule lines" against sch agreement
    LPET or LPH1?
    sara

    Hi Sara,
    It is LPET.
    Thanks & Regards,
    Kiran

  • How to use magic move with connection lines?

    When I use magic move with connection lines, they disappear and reappear in the next slide. It seems like magic move doesn't recognize the connection lines (or can't match them), so it just redraws them, instead of leaving them there.
    I'm trying to use magic move to make a nice presentation that includes connection lines. How can I make without the lines disappearing every time something moves?

    Group the shapes and connection line together:
    select the objects then Arrange > Group (alt Command G)

Maybe you are looking for