Applescript to remove first line from CSV

Hi,
I receive CSV files that I then drag and drop into a Numbers spreadsheet.
The CSV files have two lines of data (which correspond to two rows of data in a Numbers spreadsheet).
The first line in each CSV is a header that I would like to delete before it goes into the spreadsheet.
I would like to write an Applescript (application) that I could drop the CSV onto, that would delete the first (header) line.
Seems like this should be simple, but I've spent the past hour searching for how to do this and I haven't found a clear answer anywhere.
If anybody could help I'd really appreciate it.
thanks.

Saved as an Applescript App, this will delete the first line of text files dropped on the App
USE WITH CAUTION and Test
on open the_Files
     repeat with i in the_Files
          tell application "Finder"
               if name extension of i is "csv" then
                    do shell script "sed  -i \"\" '1 d' " & quoted form of POSIX path of i
               end if
          end tell
     end repeat
end open

Similar Messages

  • Need help with java File IO ( Removing the first line from a file )

    Hi guys ,
    I am currently doing a project in which I need to extract out the values from the second line of a file to the end. The question is how do I ignore the first line ??
    I thought of two possible answers myself. One is to use randomaccessfile to read and rewrite. But the file may be HUGE so storing the whole file in memory is not a very good idea.
    Second is to jump to second line before doing while ((str = in.readLine()) != EOL) ... or just delete the first line from the file. Can anyone suggest a better solution or show me some sample codes ? Thanks.
    regards
    billyam

    Just skip the first line (bufferedReader.readLine()), add a comment, and then handle the rest of your file

  • How to remove characters/lines from the beginning of an InputStream

    Hi,
    I have a program which receives several InputStreams. From each of these streams I have to remove 2 lines from the beginning. After the lines are removed, all the streams are combined to one with SequenceInputStream and read in one chunk. Is there an easy/simple way of doing this?
    One option I thought would be to read the char by char until 2 end of line chars have been detected and then read the rest of the data to a buffer. And the create a ByteArrayInputStream out of this buffer. Problem with this approach is, that the amount of data can be large, so putting all the data in to memory might cause problems.
    Another option is to use BufferredInputStream and use the readline() method twice to get rid of the lines that are not needed. After this I would write the data to some output stream, which is then converted back to input stream. Propably would work, but sound too much of work for a simple thing like this. There has to be better way.
    To make it simple, what I need is a method that looks like the following, or something similar
    *  Removes n number of lines from the beginning of a InputStream.
    *  @param is InputStream where the lines are removed
    *  @param numberOfLines int value to indicate how many lines whould be removed
    *  @return InputStream where lines have been removed.
    public InputStream removeLines(InputStream is, numberOfLines);Thanks.

    Here's the code, feel free to use it. Comments are also welcome.
    public InputStream removeLinesFromTheBeginning(InputStream is, int numberOfLines) throws IOException
              char c = 'c';
              int i = 0;
              for(int n = 0 ; n < numberOfLines ; n++)
                   do
                        c = (char)is.read();
                        System.out.print(c);
                        if(c == (char)-1)     // end of stream reached before any newline characters were found.
                             return null;
                        i++;
                   while(c != '\n');
                   System.out.println();
                   System.out.println("Characters removed:" + i);
                   System.out.println("n: " + n);
                   i = 0;
              return is;
         }Edited by: dave_spaghetti on Jun 16, 2009 5:42 AM
    Fixed a bug.

  • How can i remove a line from an ordinary text file?

    It is easy to remove a line from a file by rewriting the file. how can i remove a line without rewriting ? Also, do not use whitespaces to overwrite the line. I expect a perfect line deletion code .....

    gimbal2 wrote:
    hsc71 wrote:
    It's the way you communicate. Try to be carefull with the words you use in your post. It's easy to insult people just by choosing the wrong words. Bold text and capitals is equal to shouting.
    shock. You said "wrong words". I am seriously offended by that!
    Seriously, would you care that I am offended? I really hope not... Say what you want, people will find reasons to take offense one way or the other.Hehe, maybe you're right, but the OP still has no answer.............and in the end that's what he/she is looking for.

  • How to remove first line of outgoing messages: ?xml version="1.0"........

    On outgoing messages, when I look in MONI, I see properly formatted XML message.
    The first line of all my outgoing files has this line:
    <?xml version="1.0" encoding="UTF-8" ?>
    Is there a way to suppress this?
    If so, is there a way to suppress for only certain partners within one interface?
    Thanks,
    Jeff

    Hi Jeff,
    As others pointed without this line the document will not be a valid document. Can you tell your complete requirment. One of these kind of requirement is discussed in this thread, you can see whether its the same in your case or not. If not then tell your complete req. so that somebody can help you out here.
    Remove first line in the XML Document
    Regards,
    ---Satish

  • [svn] 4694: Don't remove text lines from the container if it isn' t the container the lines were added to.

    Revision: 4694
    Author: [email protected]
    Date: 2009-01-27 14:35:21 -0800 (Tue, 27 Jan 2009)
    Log Message:
    Don't remove text lines from the container if it isn't the container the lines were added to. When there is a state change the displayObject can be switched out from under the TextGraphic and TextBox.
    QE Notes: need to add tests - will attach my test program to bug
    Doc Notes:
    Bugs: SDK-18923
    Reviewers: Gordon
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-18923
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/graphics/graphicsClasses/TextBlockCompose r.as
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/graphics/graphicsClasses/TextFlowComposer .as

    Yup, you guys pointed me in the right direction.
    I changed my adjustmentListener to the following:
    JScrollBar scrollBar = (JScrollBar) e.getSource();
    int endLoc = document.getLength();
    try {
        Rectangle end = outputArea.modelToView(endLoc);
        if (end != null) {
            int n = scrollBar.getValue() + scrollBar.getVisibleAmount();
            boolean locked = (end.y >= n && n <= (end.y + end.height));
    } catch (BadLocationException ex) {
    }By comparing scrollbar position with the visible rectangle of the end of the document, I can now easily tell if the user has moved the tracker back or not.
    To go to the next step of automatically pausing scrolling whenever the user is moving the slider back, I also had to disable the automatic scrolling performed by DefaultCaret. Because there was no way to tell if the user was scrolling or if the output was adjusting from the adjustmentListener, I also had to flag whenever I was autoscrolling.
    The end result is a JTextPane that can be appended to at all, and locked by the user by using the slider. If new data arrives, the window is not scrolled, and any text selection the user has is not cleared. Perfect!

  • Is there a charge to remove a line from my plan?

    I have several lines on my current wireless plan.  Will there be a charge to remove any of those lines and if so, how much is the fee?

        KWildman, the more, the merrier! Why would you want to remove a line from your account? Let's talk about this.
    When accepting a two year agreement, each line has it's own contract end date. If you cancel services prior to the contract end date, then you will be billed an Early Termination Fee. This fee varies based on the device that you upgraded to and amount of months that you've completed on that contract. For more information regarding your customer agreement and how the Early Termination Fee is calculated, click http://bit.ly/17srsZb
    Lasina_VZW
    VZW Support
    Follow us on Twitter @VZWSupport

  • How to remove new line from string

    I have a string say following
    String line = "one\ntwo\nthree";Now i am trying to remove new line from string. For this i did following
    String txt = line.replaceAll("\\n","");But i see still new line is occuring. Is it correct way. Please advice me.

    Ok. I was just using \n instead of \r\n. And i am in windows. I will give a try with \r\n
    Ok i tried using following , but it doesnt work.
    line = line.replaceAll("\\r\n","");Am i missing anything here. Please guide me.
    Edited by: ArpanaK on Oct 8, 2007 4:44 PM

  • How do i remove a line from my family plan?

    I need to remove a line from my family plan, how do i do it on the computer?

    You can't cancel service on-line; you'll need to either call Customer Service or visit your local Corporate Verizon store.

  • Remove xml first line from generated VO xml

    I'm combining multiple xml file to generate report using BIPublisher. I generated xml based off of a VO using VO.writeXML. How do I remove first row (<?xml version="1.0"?>) in the xml?

    use Transformer and set setOutputProperty to omit first line.
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    Edited by: Puthanampatti on Dec 6, 2012 6:42 PM

  • Removing first line in text file... Memory and HD concern

    Hello all,
    I want to remove the first line of a text file. This is easy... One way
    to do it, is to find the first "end of line" caracter, strip the string
    and re-write the sting in file with the "strip to sreadsheet" VI.
    Since the file can be quite large (about 120000 lines), is this a good
    way to do it. Will it re-write all the line or just moving the "begin
    of file" pointer to the second line? If it re-write the whole file,
    this option is not very good since I could have to do this operation
    quite often. (I want the file to be a kind of circular buffer / backup).
    What do you think is the best way to do this?
    Thanks!
    Vincent

    I think you would have to read in all the data and write it to a new file, you could either keep the data in RAM or simply write to another file then delete the original, and then rename the temp one.  So obviously that is a lot of data and memory.
    My main question is are you trying to use a text file as a circular buffer?  If so can you tell us more about the data, ie is it strings of a constant length?  Does a user ever need to read the file or could we head binary?
    A solution would be to truly make the file a binary file, so you could actually seek through the file easier, and maybe make the first data chunk the location of the most recent write.  The obvious danger is then writing over existing data.  This solution is still risky because of the data writes.
    You may want to look at some of the other file formats like HWS which maintains a hierarchy of data for you so you can simply add and remove data from it.  However, a user will not be able to easily read it.

  • Remove blanco line from poplist

    Hi,
    How do I remove a blanc line from the poplist? I've first entered 4 items in the list item property of the poplist. The insert property is set to no, required is set to yes and initial value is '0'
    Now I want the last item to be removed:
    If I simply delete the list item and the value a blanc line appears when running.
    I've also used 'ctrl + <'. This removes the item but when trying to compile I receive an error because the blanco items under the line that I've deleted contains LIST38, LIST39, ... as value. This doesn't correspond with the max length of 1.
    Any idea?
    Thanks

    I've solved it.
    I've also deleted the last item that I actually didn't want to deleted and everything beneed it with ctrl + < and than add it the item again.
    Thanks for your time.
    Regards

  • Remove Second Row From CSV

    I've got a group of small CSV files - only about 15 and with about 30 rows each in. I'm running a script against them once a month so because they're so small and being processed infrequently they can read-in and treated as a string. I need to remove the
    second row of the file though and I've got nowhere with it so far.
    Sample data:
    TimeIndex,CPU,FCP,NFS,CIFS,ISCSI,NetworkIn,NetworkOut,NetworkTotal,Filername
    TimeIndex,CPU,FCP,NFS,CIFS,ISCSI,NetworkIn,NetworkOut,NetworkTotal,000-samplehostname
    So the header is correct, but the sample hostname on the second row would be different for each file and that row shouldn't be there. The simplest thing to do is just wipe that row entirely.
    Any ideas?
    Thanks in advance
    Adam

    I have two ideas :-)
    You mentioned that you are just reading in the files and treating them as strings.  In this case, you'd want to split it to a collection of objects and remove the second row...like this:
    $strMultiLineString = "Test
    Test
    Test"
    $arrlines = {$strMultiLineString -split "`r"}.INvoke() #Force it into an object collection
    $null = $arrlines.Remove($arrlines[1])
    If you are importing the file as a csv, you could do something like this:
    $csv = {Import-CSV -path "C:\Temp\Test.csv"}.Invoke()
    $null = $csv.Remove($csv[1])
    Here is more information on adding and removing items from arrays/collections:
    http://www.jonathanmedd.net/2014/01/adding-and-removing-items-from-a-powershell-array.html
    That should remove the line in question, but is only done in memory, sounds to me the OP wants it removed from the file, so you would need to save the changes back to the actual file
    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
    Don't Retire Technet

  • How can I remove a line from a file?

    how ca i remove one or more than one line from a text file?

    Open the file for input.
    Open another file for output.
    Read each input line.
    If you want to delete it, go get the next line
    Otherwise, write the line to output, and go get the
    next line.
    Close both files.

  • Trying to omit first line of CSV file (the header)

    Hello everybody,
    Newbie here havin a lil problem. I have this program below that reads in a CSV file. My test CSV file has the follow structure:
    ID, LastName, FirstName, Phone, Email,
    2345, Yez, Wei do, 456-789-0123, [email protected],
    2744, Avanto, Aldo, 562-593-6500, [email protected],
    1212, Dewy, Cheatem, 123-456-7890, [email protected],
    1234, No, Wei Foo, 123-456-7890, [email protected],
    The first line is my header. (here is the heart of my problem)
    I have the program reading in the file and the it sorts it. The problem i have is that the first line, my header gets sorted with everything else. Here is my feable attempt with resulting error:
    import java.io.*;
    import java.util.*;
    public class File2Array {
        public static void main(String[] args)
            File file = new File("person_test1.csv"); //File to read in
            ArrayList persons = (ArrayList) getPersons(file); //call to arraylist
            Collections.sort(persons);
            for (Iterator i = persons.iterator(); i.hasNext(); )
                System.out.println(i.next());
        public static List getPersons(File file)
    //NEW PIECE OF CODE        boolean first = true;
            ArrayList persons = new ArrayList();
            try {
                BufferedReader buf = new BufferedReader(new FileReader(file));
                while (buf.ready()) {
                    String line = buf.readLine();
    //NEW PIECE OF CODE
         while( ( line = buf.readLine() ) != null )
              if( first )
                   first = false;    continue;
    //ORIGINAL IF
         //   if (!line.equals("") )
    //NEW IF
                    if (line != null && !line.equals("") )
    //END OF NEW CODE
                         StringTokenizer tk = new StringTokenizer(line, ",");
                         ArrayList params = new ArrayList();
                         while (tk.hasMoreElements())
                             params.add(tk.nextToken());
                         Person p = new Person(
                                 (String) params.get(0),
                                 (String) params.get(1),
                                 (String) params.get(2),
                                 (String) params.get(3),
                                 (String) params.get(4));
                         persons.add(p);
            } catch (IOException ioe)
                System.err.println(ioe);
            return persons;
    class Person implements Comparable
        private String ID;
        private String LastName;
        private String FirstName;
        private String Phone;
        private String Email;
        public Person(
            String ID,
            String LastName,
            String FirstName,
            String Phone,
            String Email)
            if (FirstName==null || LastName==null)
                throw new NullPointerException();
            this.ID = ID;
            this.LastName = LastName;
            this.FirstName = FirstName;
            this.Phone = Phone;
            this.Email = Email;
        public String toString()
            StringBuffer sb = new StringBuffer ();
            sb.append( ID );
            sb.append(" ");
            sb.append( LastName );
            sb.append(" ");
            sb.append( FirstName );
            sb.append(" ");
            sb.append( Phone );
            sb.append(" ");
            sb.append( Email );
            sb.append(" ");
            return sb.toString();
        public boolean equals(Object o)
            if (!(o instanceof Person))
                return false;
            Person p = (Person)o;
            return p.FirstName.equals(FirstName) &&
                   p.LastName.equals(LastName);
        public int hashCode()
            return 31*FirstName.hashCode() + LastName.hashCode();
        public int compareTo(Object o)
            Person p = (Person)o;
            int lastCmp = LastName.compareTo(p.LastName);
            return (lastCmp!=0 ? lastCmp :
                    FirstName.compareTo(p.FirstName));
    this code compiles and runs but does not produce any output and I don't understand why.
    Question: What is the proper way to have the code omit the first line of a CSV file??
    By the way I do have another file called person.java that goes with this but I didn't think I had to post it.
    Also am I posting correctly? Am I putting in too much code??
    Than you!!

    Hot diggity! jverd,
    I got it to work!! here's what I did all thanks to you :-)
    ArrayList persons = new ArrayList();
            try {
                BufferedReader buf = new BufferedReader(new FileReader(file));
                //read through file and populate array
                //while (buf.ready()) {
                    String firstline = buf.readLine();  //gets header, renamed line to firstline
                    String line;                  //added this line     
                    System.out.println(firstline);     //added this to print out firstline     
         //try this
              while( ( line = buf.readLine() ) != null )
              /*{                    //commented out this portion
              if( first )
                   first = false;    continue;
              //end try this                
                    //if (line != null && !line.equals("") )     //down to here
                    if (!line.equals("") )          //added this
                         StringTokenizer tk = new StringTokenizer(line, ",");
                         ArrayList params = new ArrayList();
                         while (tk.hasMoreElements())
                             params.add(tk.nextToken());
                         Person p = new Person(
                                 (String) params.get(0),
                                 (String) params.get(1),
                                 (String) params.get(2),
                                 (String) params.get(3),
                                 (String) params.get(4));
                         persons.add(p);
                      }                       

Maybe you are looking for

  • Trouble Installing CS4 on Mac Book Pro with Lion 10.7.3

    Hello, I'm having trouble with this. As instructed by Adobe I'm working with the original CD to install this to my laptop. It goes up to installing Adobe Air, about half way through the whole installation and then stops. I have tried resetting the pe

  • Using CTRL-SHIFT-F for searches, can the cursor please be in the search window by default?

    I regularly use CTRL-SHIFT-F to search particular folders (usually the Inbox) for a text string. When the search screen comes up, I sometimes start typing the text string, assuming that naturally the cursor's default position is in the search window.

  • Generate arabic pdf in oracle report 10g

    what is the right way to generate arabic language in oracle report 10g destype=PDF?? i do that for font < arial > and < transparent arabic > but i have a problem with some arabic font like < simpilified arabic > and i put this font in utifont.ali

  • How to figure a datsource underlying tables

    Hi, I want to find out if there is any standard procedure to figure out the underlying tables of a particular data source both standard SAP and  Non SAP? I know that for Logistics (LO) we can find it from the maintenance option of LBWE

  • Webdynpro Java based application performance testin

    Hi Experts, could any one of you please provide me step by step guide to use some tool which can be used for profiling webdynpro java based application? this is very urgent...... kindly help Best regards Falgun