Redirecting output after a "cat" command

I first encountered this with "do shell script" in AS, and the issue also occurs in Terminal.
Basically, I want to get contents from a file, make some changes via "sed ," and return the changed version to the same file -- but the file always winds up empty. Without the redirect, the commands work as expected.
For example, in Terminal:
cat --path to some file-- | sed 's/this/that/g'
results in the expected changes (returned to Terminal)
but
cat --path to some file-- | sed 's/this/that/g' > path to some (same) file
results in a blank file
(The "sed" command isn't even necessary for this to happen; just trying to return the output of the "cat" command to the file results in a blank file.)
I've certainly been able to accomplish this sort of thing with commands other than "cat." Is this something that's not possible with "cat" or do I have the syntax wrong?
(Of course, I can get around this by following up with an "echo" command but, in "do shell script," that requires more code.)
Thanks in advance for your comments.

HI osimp,
   I've always thought that the "sed 's/this/that/g' < input > output" syntax looked cool because you can sort of see the flow of information. However, the end of the command is simply a pair of redirect directives. The first tells the shell to open the file and pipe the contents into the standard input stream of sed. Then the output of sed is piped into the output file.
   The command I was proposing, "sed 's/this/that/g' input > output", is simpler in that it tells sed to read the file directly rather than asking the shell to read it.
   You said above that you were interested in storing the result in a variable. That could be done simply with a command like:
OUTPUT=$( sed 's/this/that/g' input )
For many types of content this would work nicely but the shell will try to expand the output so plenty of things can cause errors. I was going to wait to post the above until I discovered a way around that expansion but I haven't had enough time to do that so I'm posting it and I'll see if I can improve it later.
   I know some about AppleScript and have written several scripts that combine capabilities of the shell with those of AppleScript. There are probably more people here that know AppleScript here than there are shell scripters on the AppleScript Discussion. You should try posting the whole question over here as well as over there. However, try and see if you can get the help of Deivy over there. He knows a lot about interactions between AppleScript and the shell.
Gary
~~~~
   A memorandum is written not to inform the reader,
   but to protect the writer.
         -- Dean Acheson

Similar Messages

  • How to redirect output of an OS command to a stream???

    how can i redirect the output of an OS command (such as 'ls' in linux or 'dir' in windows) to a io stream???
    ....for example, assume i'm having a textbox and a button...when i click the button , i need the output of 'ls' to be in the textbox....i think execution of the command could be accomplished by Runtime's exec() ...but how to redirect outputs???

    You should find what you are looking for here:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Redirecting output to J2EE server command prompt

    I am finding difficulty with reading the system.out.println() given in the server side code. J2SDK redirects it to System.out file, but most of the time, I am not
    getting the results. I tried to restart the server to get the value from buffer.
    But thats not working either. Is there any way for getting the output in the server prompt itself. Can I do any configuration changes for this.

    Start the J2EE server from the command prompt with "-verbose" option.
    Regards,
    Ashoke Bhowmick

  • Redirecting output in Netbeans?

    After a few years of several languages, I am finding Java to be my home :) I really enjoyed the improvements that Sun has made with NetBeans 6. However, it doesn't output text to the console/command-prompt like it would in JCreator Pro. Even in JCreator Pro, I had to redirect the output and it was much easier given a few settings. For Netbeans, the output goes to an "Output Window." I find writing my ascii game is easier with the command prompt and so JCreator seems ideal if I can't get my preferred IDE set properly for the command prompt. Is there a way to get NetBeans to redirect its output from the Output Window to the command prompt? Thanks.

    I was able to get the "run" button to execute output to the console (command prompt). Doing so was not too difficult. I agreed with Leonardo that posting it here would be helpful for someone else. He was very helpful with our first few attempts on a similar task.
    In your workspace, click on the Files tab. Find build-impl.xml, double-click on the "run" property in the navigator window. It should bring you to something similar below. What I added was the "exec" open and end tags. Just paste this in there and you will be up and going.
    <target name="run" depends="init,compile" description="Run a main class.">
    <j2seproject1:java>
    <customize>
    <arg line="${ application.args}"/>
    </customize>
    </j2seproject1:java>
    <exec executable="cmd">
    <arg value="/k" />
    <arg value="start cmd /k java -classpath "${basedir}\${ build.classes.dir}" ${main.class}" />
    </exec>
    </target>

  • Not getting full output  through prtdiag -v command

    Dear all
    I am not getting the "Environmental Status", "FRU Status" & "FW Version:" through prtdiag -v command. Here is the output of the command :
    # prtdiag -v
    System Configuration: Sun Microsystems sun4v SPARC Enterprise T5220
    Memory size: 32640 Megabytes
    ================================ Virtual CPUs ================================
    CPU ID Frequency Implementation Status
    0 1167 MHz SUNW,UltraSPARC-T2 on-line
    1 1167 MHz SUNW,UltraSPARC-T2 on-line
    2 1167 MHz SUNW,UltraSPARC-T2 on-line
    3 1167 MHz SUNW,UltraSPARC-T2 on-line
    61 1167 MHz SUNW,UltraSPARC-T2 on-line
    62 1167 MHz SUNW,UltraSPARC-T2 on-line
    63 1167 MHz SUNW,UltraSPARC-T2 on-line
    ======================= Physical Memory Configuration ========================
    Segment Table:
    Base Segment Interleave Bank Contains
    Address Size Factor Size Modules
    0x0 32 GB 8 4 GB MB/CMP0/BR0/CH0/D0
    MB/CMP0/BR0/CH1/D0
    4 GB MB/CMP0/BR0/CH0/D1
    MB/CMP0/BR0/CH1/D1
    4 GB MB/CMP0/BR1/CH0/D0
    MB/CMP0/BR1/CH1/D0
    4 GB MB/CMP0/BR1/CH0/D1
    MB/CMP0/BR1/CH1/D1
    4 GB MB/CMP0/BR2/CH0/D0
    MB/CMP0/BR2/CH1/D0
    4 GB MB/CMP0/BR2/CH0/D1
    MB/CMP0/BR2/CH1/D1
    4 GB MB/CMP0/BR3/CH0/D0
    MB/CMP0/BR3/CH1/D0
    4 GB MB/CMP0/BR3/CH0/D1
    MB/CMP0/BR3/CH1/D1
    ========================= IO Configuration =========================
    IO
    Location Type Slot Path Name Model
    MB/PCIE PCIE MB /pci@0/pci@0/pci@1/pci@0/pci@1/pci@0 pci-pciexclass,060400
    MB/NET0 PCIE MB /pci@0/pci@0/pci@1/pci@0/pci@2/network@0 network-pciex8086,105e
    MB/NET1 PCIE MB /pci@0/pci@0/pci@1/pci@0/pci@2/network@0,1 network-pciex8086,105e
    MB/NET2 PCIE MB /pci@0/pci@0/pci@1/pci@0/pci@3/network@0 network-pciex8086,105e
    MB/NET3 PCIE MB /pci@0/pci@0/pci@1/pci@0/pci@3/network@0,1 network-pciex8086,105e
    MB/PCIE PCIE MB /pci@0/pci@0/pci@2/scsi@0 scsi-pciex1000,58 LSI,1068E
    MB/PCIE1 PCIE 1 /pci@0/pci@0/pci@8/pci@0/pci@1/SUNW,emlxs@0 SUNW,emlxs-pci10df,fc20LPe11000-S
    MB/PCIE0 PCIE 0 /pci@0/pci@0/pci@8/pci@0/pci@9/SUNW,emlxs@0 SUNW,emlxs-pci10df,fc20LPe11000-S
    ========================= HW Revisions =======================================
    System PROM revisions:
    OBP 4.27.1 2007/09/14 15:17
    IO ASIC revisions:
    Location Path Device Revision
    MB/PCI-SWITCH0 /pci@0/pci@0 pciex10b5,8533.aa 170
    MB/PCI-SWITCH2 /pci@0/pci@0/pci@1/pci@0 pciex10b5,8517.ad 173
    MB/PCI-SWITCH1 /pci@0/pci@0/pci@8/pci@0 pciex10b5,8533.aa 170
    MB/GBE0 /pci@0/pci@0/pci@1/pci@0/pci@2/network@0 pciex8086,105e.108e.105e.6 6
    MB/GBE0 /pci@0/pci@0/pci@1/pci@0/pci@2/network@0,1 pciex8086,105e.108e.105e.6 6
    MB/GBE1 /pci@0/pci@0/pci@1/pci@0/pci@3/network@0 pciex8086,105e.108e.105e.6 6
    MB/GBE1 /pci@0/pci@0/pci@1/pci@0/pci@3/network@0,1 pciex8086,105e.108e.105e.6 6
    MB/SAS-SATA-HBA /pci@0/pci@0/pci@2/scsi@0 pciex1000,58.1000.1000.2 2
    Kindly help me in getting that information from prtdiag command as I have check that picld deamon is running on the system also & service is in online status . This system is running solaris 10 OS.
    Regards

    Hi
    I would like to know if I restart the picl service in solaris 10 on production server, will it have any effect on the production server. As I think that may be, I will get the proper output after restarting the daemon.
    Regards

  • -bash:  cat: command not found (or grep)

    Hi, Strange things:
    i3: okn$ ls -R | grep -h "dof" | cat > dtext.txt
    -bash:  cat: command not found
    or then I get this:
    i3: okn$ find . -type f -print | grep -c
    -bash:  grep: command not found
    but this is not happening all the time, i remember grep or cat did work once or twice...
    What's going on here?
    OS 10.7.4; repaired permissions
    Any assistance much appreciated!
    / bw, Omar KN

    'cat' is stored in /bin/cat, NOT /usr/bin/cat, which explains the file not found messages above.
    HOWEVER, the information you have provided seems to imply you have the executables, and previous information provides says you have a valid PATH:
    echo $PATH
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/bin:/bin:/usr/sbi n:/sbin:/usr/local/bin:/usr/X11/bin
    this creates a mystery as to why you are getting:
    -bash:  cat: command not found
    -bash:  grep: command not found
    I have a couple of thoughts.
    a) I'm wondering if you have any 'alias' statements in your .bash_profile (or .bash_login, or .profile, or .bashrc).
    b) if you would get the same results should you rename your .bash_profile (and/or .bash_login, .profile, .bashrc) to something like saved.bash_profile, then restart your terminal session (basically eliminating any personalized shell customization).
    c) what would happen if you created a new account (System Preferences -> Accounts) - basically a clean starting point.
    d) are you executing these commands from the command prompt?  Or from within a shell script?
    d.1) if from within a shell script, is the script file the correct file format.
    file name.shell.script
    you want to check that the output from the 'file' command DOES NOT say "...with CRLF line terminators...", as that would imply the the file came from (or through) a Windows system.

  • I can't print any web page. after the print command, it wants to save xps files. on cannon printer. vista system

    can't print any web page. after the print command, it wants to save as a xps file.
    == This happened ==
    Every time Firefox opened
    == after up grade to 3.6.6 ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C)

    I found that Firefox/XPS had deleted all printer driver setups except for the XPS connection. I had to reinstall my printer connection in order to have that selection present in the printer dialogue box.

  • How to restore views and procedures after drop user command?

    How to restore views and procedures after drop user command?
    We have 817 EE on NT and one developer created a lot of procedures, functions and vews. DB was not backuped and archived and export has not been done - our fault and we understand it. Sorry for this.
    Ok, now the story: another developer dropped this db user and we lost everything: procedures, functions and vews. The new user with trhe same name was created and new schema was imported in this user, but all old objects are lost. We don't have export and backup and archive log files.
    Question: may we can restore this lost stuff from some other sources. We are looking for lost codes, not data. May be we can use redo logs or shared pool or any other things. Any idea will be appreciated.
    Thanks.
    Victor
    [email protected]

    The switch has occurred after user was dropped, the data has been overwritten and there is be no way to use redo log files.
    I would like to explore another opportunity. Is possible to use Shared Pool or any Data Dictionary internal information to restore texts of the lost SQL and PL/SQL scripts executed in this DB before user was dropped? Not too many scripts are executed in this DB and the lost ones may still be in stack. I remember that Shared Pool (cash) should keep last executed scripts in order to improve performance. They probably are kept in some special format. Can we restore these scripts? Of course they also might be pushed out by Import that had been done after user was dropped.
    Thanks for your help,
    Victor

  • Web Auth Type: Customized(downloaded) Redirect URL after login not working.

             5508WLC as anchor controller with WLC1 and WLC2 with WCS. I have 2 public ssids set up to go directly to the internet.
    Everything is working as it should.  I downloaded the web auth bundle from Cisco and  will just use a disclaimer page and then if the user clicks on the accept button they will be redirected to our company web page, and then they can get out to the internet.
    I have edited the aup.html and login.html to say what I want it to.  I have 2 different login.html pages and bundle to a .tar file like the documentation says.  I download it via tftp to the controller and it is successful. The disclaimer page opens up when I connect and it looks as it should.  The problem is I cannot seem to get the accept button to work. It redirects to a web page but it is undefined. 
       I must be missing some setting somewhere, but I just can not seem to find it.  Is there any line I need to edit in the login.html files that will redirect the page.    The config on the Web Login Page  Redirect URL after login is http://www.mccg.org which is our home page.
    Any help will be appreciated.  I cannot seem to fine very good documentation, or I am just overlooking something.
    Thanks
    John   

    Your HTML code is wrong. Attach your code if your okay with it and I can check.
    Sent from Cisco Technical Support iPhone App

  • Capturing the output of a os command line

    I need to capture the output of a os command line executed from one java program and I don't know how can do it.
    For example:
    Runtime.getRuntime().exec("hostid");

    Your suggestion worked very well, just in case that this could interest somebody, this is the complete solution
    Thanks for your help
    import java.io.*;
    public class HostID
    public static void main(String args[]){
    try{
    InputStream in = (Runtime.getRuntime().exec("hostid")).getInputStream();
    byte[] arreglo= new byte[200];
    int cantidad = in.read(arreglo);
    System.out.println(new String(arreglo,0,cantidad));
    } catch (IOException ioe){System.out.println(ioe.getMessage());}
    }

  • Create .txt empty file After Message Processing Command Line Linux command

    Hi All,
    An empty .txt file has to be created in FTP location(FTP loc c:\xyz\Customer20082910.txt) only after the .dat file has been created(FTP loc c:\xyz\Customer20082910.dat)
    Note:.dat has the actual data and .txt is an empty file and is created only after .dat is created
    I know that .txt empty file can be created using the After Message Processing Command Line...
    But confused which command to be given such that it will be created in the FTP location(c:\xyz\Customer20082910.txt)
    Can any one please give the Linux command for it...
    Regards,
    Sridhar

    Hi Aamir,
    Thanks for the suggestion, I will ask my client to create a shell script at FTP server...
    And one more question,
    This is reverse side , now the .dat file is to be picked only if .txt exists at the FTP server (scenario File > XI>SAP) (earlier was SAP>XI>File)..
    So please can you suggest for this also...
    How can i check for the .txt and pick corresponding .dat file...
    i had posted question long back
    Need to pick .TXT file only if .CTL file is available
    Regards,
    Sridhar

  • After using shift command 4 and send to desktop,how can I had iphoto to the list "open With" to preview menu?

    After using shift command 4 to send a photo to the desktop, how can I add iphoto to the list of"open with" menu ?

    All that's doing is forcing iPhoto to import the image.  Dragging it to the iPhoto icon will do the same, or create an automator action and save it as a Contextual menu item.
    Regards
    TD

  • My audio stops outputting after a few songs in a playlist - itunes says its still playing, stopping and starting track recommences audio output.  Mac book Pro Lion 16gb ram

    My audio stops outputting after a few songs in a playlist - itunes says its still playing, stopping and starting track recommences audio output.  Mac book Pro Lion 16gb ram.  Can be any song, any time, same song will play if I select it again.  Bit of a bummer itunes is the main thing I use (macbook pro jukebox).

    Most likely culprit is your Lacie drives which are notorious for flaky power supplies which cause just the sort of erratic behaviour that you describe. Have had similar issues myself. Lacie has been good about replacing my power converter-- twice. If you have seven of them, good luck finding the bad one or more. Like I said, the behaviour is erratic. Sometimes it'll work sometimes not. I can't comment on Samsung drives because I've never used them and have never heard anything about them. Same with Softraid. Why not just use Disk Utility. Sounds like you're ready for an external hardware raid. This will be much faster, much more reliable, and may even be cheaper than seven firewire drives. Check out G Tech, and Maxx Digital for starters.
    Best of luck
    Terry

  • JS RangeError exception happens after click a command link in Chrome22

    Hi,
    I am using JDev 11.1.1.4. I got an JS exception after click a command link. Following is my steps.
    1. use chrome(V22) to access my app
    2. refresh page
    3. click a command link(with action property) in UI which can jump to another page
    Result: nothing happens, and since then click any command link does not work(page does not refresh and no reqeust is sent). But command button still works.
    If we do not refresh page, this does not happens.
    This case occurs always in Chrome and occasionaly occurs in FF.
    Troubleshoot:
    after refresh page, an ajax request is sent in ADF js framework. Respense is recieved and callback funtion is executed. Excetpion happens during callback function executing period.
    Watch call stack, the exception happens during removeComponent(name is like this) funtion.
    And finally, an exception is caught. Here is detal of exception:
    Excetption: RangeError, type: stack_overflow, stack: undefined.
    Any one got this case?
    Please give some help and guidance.
    Thanks

    Hi,
    if you have a customer support contract, can you file a service request with support and provide a test case ? Also, worth trying this with JDeveloper 11.1.1.6 first
    Frank

  • Frm-90928 positional parameter after key on command line

    frm-90928 positional parameter after key on command line
    I have an error while i run form module. i am using database 9i with 9iDS. Plz help me to resolve this issue.

    Exactly Francois, 100% true.
    I've noticed that the Forms Builder tries to run the unsaved forms from the user's default home (root) directory, which almost always in windows environment has spaces in it, like "Documents and Settings\...".
    Tony

Maybe you are looking for

  • Can't send mail after security update

    Hello, I installed a security update friday night, and can no longer send email using either Mail 2.1 or Thunderbird. Both were working prior to the security update. I am not getting any error messages except for the ones over the phone that go..."di

  • OAM (authorization and authentication)

    Does OAM offer any cape Web Services for the authorization and authentication? Thanks in Advance, Awaiting sooner response. Edited by: Odemail on 05-abr-2012 8:31

  • Configure portal to issue ticket (MYSAPPSSO2 cookie) for "higher" domain

    Hello all, we have an EP 7.00 (SP 22) which can be accessed using the following (faked) fully qualified URL: https://host.sd1.sd2.mycompany.de:[HTTPS-port]/irj/portal When logging on to the portal with username and password, the portal issues a logon

  • IPod 4th generation stuck on flashing apple logo

    So i tried to update my software and it got stuck on a flashing apple screen. I'm trying to reset through iTunes, but my iPod isn't recognized in iTunes when I put it in DFU mode. Still stuck on flashing apple screen. What should I do?

  • JSLinks affects multiple web parts

    I have a page with two list view web parts one pointing to pages library and another to a custom list and created custom jslinks to render them and notice that one of the two jslinks affects both web parts, the second jslink has no effect. How to res