open and edit file at command prompt

This is a discussion on open and edit file at command prompt within the C++ Programming forums, part of the General Programming Boards category; Hi there I would like to be able to open a file and display at the command prompt, and then ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    4

    open and edit file at command prompt

    Hi there

    I would like to be able to open a file and display at the command prompt, and then be able to edit the screen data, and save it back out to the file. Is this possible?
    The reason I am doing it at the command prompt is because this is a uni assignment. Of course I have no problem in opening a text file to the screen and saving data on the screen out to a file, my problem is editing data loaded from a file on the screen.

    Any help would be appreciated.

    Thanks.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Well you couldn't write a program to manipulate the data in window's standard command prompt. What you could do is, display the information in the file, then have commands that you can pipe the text through to edit the file.

    ...but then unix already has that command.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    4
    heh SlyMaelstrom

    what is the unix command. The program will be compiled in unix, I am only writing it on a windows machine.

    thanks

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    There are lots of Unix commands to manipulate text in a file. Just look up Unix commands. One example is awk.

    Code:
    $ cat hello.txt
    Hello, Sally!
    Hello, Jimmy!
    Hello, Betty!
    Hello, Michael!
    $ cat hello.txt | awk -F, '{print $1}'
    Hello
    Hello
    Hello
    Hello                  
    $ cat basket.txt | awk -F, '{print "Goodbye, " $2}'
    Goodbye, Sally!
    Goodbye, Jimmy!
    Goodbye, Betty!
    Goodbye, Michael!
    Note, I wrote this by hand, it wasn't actually passed in Unix Command Line. So if there is a syntax error, sorry.
    Last edited by SlyMaelstrom; 10-22-2005 at 12:03 AM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. edit txt file help
    By pczafer in forum C++ Programming
    Replies: 4
    Last Post: 04-20-2009, 07:49 AM
  2. tmpnam() : permission denied when try to open temp file
    By happyclown in forum C Programming
    Replies: 3
    Last Post: 03-16-2009, 11:48 PM
  3. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21