[SOLVED] Removing brackets from file - python/sed

I wrote a small python-script in order to do some manipulation of columns. I'm quite unexperienced, and i stumbled upon a problem i didn't manage to solve:
When the script is finished with the data manipulation, everything is stored as data type "list", which implies the following form when i output the data with print: ['2321321', '321321321', '55555']. I don't want the brackets and ' (since i want to import the data into a spreadsheet). I've tried to make a loop to print out list content, but then i get everything in one column, which i don't want. (Something like: for l in line: print l )
Is there a way to print lists without the brackets and '? I tried to solve it with sed, but my knowledge of that program is zero, and no success. My solution was to open the output in a text editor and use search and replace, which is very tedious work for 50 files.

I think the quicker way is using the join() method:
[andyr@roo ~]$ python
Python 2.4.1 (#1, Apr 5 2005, 11:00:51)
[GCC 3.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> items = ["one", "two", "three"]
>>> allitems = " ".join(items)
>>> print allitems
one two three
Of course, you could have "," or "t" (tabs), etc to delimit the columns rather than the space in the above example.

Similar Messages

  • [solved]remove backslashes from file names?

    Hi!
    I have a lot of files that contain backslashes in file name, spread over many many folders.
    How do I remove that character from all file names? The approaches / scripts / programs I usually work with can't handle the invalid file names (e.g. loose the '\' and then 'cant stat()' -.-").
    Thanks!
    edit: Argh... now I've got copies of half of the files without the "\" in the same folders, because copying did work on most but deleting only on some... also multiple \\\ because I messed up one sed line. and "echo" failed to warn me about the result, just dropping a few \ while mv didn't... or something. So confused.
    Last edited by whoops (2011-02-22 00:22:58)

    sisco311 wrote:#!/usr/bin/env bash
    while IFS= read -rd '' file; do
    dirname="${file%/*}"
    basename="${file##*/}"
    mv --backup=numbered -- "${file}" "${dirname}/${basename//\\/_}"
    done < <(find /full/path/to/dir -depth -name '*\\*' -print0)
    Thanks, that did it!
    Don't know what exactly I've been doing wrong, but it seems not to happen any more since I try to do stuff with "while, read, ${}"  instead of "for, $(), echo, sed"
    pulce wrote:Not sure that's the point, but backslash is an escape
    Yes, I know, that was the problem. That's why those stupid things always keep either disappearing or multiplying - I guess I just suck at keeping track of what program handles them which way and depending on what.
    Last edited by whoops (2011-02-22 00:15:30)

  • [solved] Remove words from file using a list variable?????

    Is it possible with bash, to create a script that will scan a text file and remove words that are set in a list?
    I have a file with words like so:
    word1
    word2
    word3
    I would like to be able to set script to scan file and remove only the words (and spaces left) that are in a list,
    that is inside script. Is this possible???
    Last edited by orphius1970 (2010-04-22 12:05:45)

    sorry I am new to scripting and Have NEVER used sed.
    Can you explain a little better?
    Ok i tried it and understand a little better. However,
    It left space behind. How do I fix that?
    Also, how do I get it to save the file with the changes?
    Sorry If I seem so noobie
    Last edited by orphius1970 (2010-04-22 11:27:18)

  • Removing date from file name

    Hello,
    Is there any way to move all the file from one location to another and remove the datepart from filename.
    for eg:- if file name is abc_20150411.xls change to abc.xls. if file name does not contain date part then ignore it.
    Can any one suggest if its possible.
    Thank You

    Hi ,
    I have created package based on your question and decribed in detail in below post:-
    https://msbitips.wordpress.com/2015/04/12/ssis-removing-datestamp-from-file-name-when-moving-from-one-location-to-other/
    You need package code, just add comment in this thread.
    Thanks
    Prasad
    Mark this as Answer if it helps you to proceed on further.

  • How to remove DRM from files

    I thought iTunes Match was supposed to remove DRM from files

    royfrommanhattan wrote:
    I thought iTunes Match was supposed to remove DRM from files
    It doesn't actually  "remove" anything.  But it does allow you to delete the DRM versions and download non-DRM versions, if available.
    Go to this document, and read the section on "Can I upgrade my previously purchased music to iTunes Plus?":
    http://support.apple.com/kb/HT1711

  • Remove words from file

    Hello, I have created a class which is supposed to be an array of stopwords (words that I want to remove from a file).
    Then I want to create another class which reads in a file. It reads the file. Then it looks through the array of stopwords. If it encounters a word in the file which is the same as the word in the array, it replaces it with nothing.
    I want this class to be separate from the main class so that in the main class,I can specify any file, and the stopwords will be removed. Here is some code, thanks
    import java.io.*;
    import java.util.*;
    public class StopWordArray {
         //This class represents an array of stopwords
         //The stopwords are read from a text file into an array
         private String [] tokens;
         //constructor
        public StopWordArray(){          
             try{
    //         open input stream
             File inputFile = new File("/home/myrmen/workspace/Chisquare/extract/stopWordList.txt");
             InputStream inStream = new FileInputStream(inputFile);
             InputStreamReader inreader = new InputStreamReader(inStream, "8859_1");
             BufferedReader reader = new BufferedReader(inreader);
            String line;
            //Fills array
            while ((line = reader.readLine()) != null) {
            StringTokenizer st1 = new StringTokenizer(line);
            int numberOfElements = st1.countTokens();
             tokens = new String[ numberOfElements ];
            int index = 0;
             while( st1.hasMoreTokens() )
               String element = st1.nextToken();
             tokens[ index ] = element;
                       index ++;
            reader.close();
           catch (Exception ex) { ex.printStackTrace(); }
    import java.io.*;
    import java.util.StringTokenizer;
    public class RemoveStop {
         //Fields
         private StopWordArray myArray = new StopWordArray();
        private String myString;
         //Constructor
        public RemoveStop(String myString){
    import java.io.*;
    public class Main {
         public static void main(String[] args) {
              StopWordArray theWords = new StopWordArray();
            theWords.printArray();
            String file = "/home/myrmen/workspace/Chisquare/extract/Turing";
            RemoveStop remove = new RemoveStop(file);
    }

    Ok, here is an update:
    private String [] tokens;
       //Method which returns each element in the array as a string
        public String word()
        String word = null;
        for(int i = 0; i < tokens.length; i++)
        word = tokens.toString();     
    return word;
    public void readFile(){
    String output = null;
    StringTokenizer st1 = new StringTokenizer(aString);
    while(st1.hasMoreTokens())
    String element = st1.nextToken();     
    //System.out.println(myArray.word());
    if(element.equals(myArray.word()))
    output = element.replaceAll(myArray.word(), "WAY");
    //else{System.out.println("ERROR");
    System.out.println(output);
    But with the readFile() method, I only access the LAST element of the array. How can I iterate through the whole array, and search for the words that are stored in the array in the input file?

  • [solved] remove packages from a txt file list

    as the subject header says, I want to run "pacman -R" and have it read a list of packages from a text file.
    Is this possible????
    text file is formatted as such....
    file1
    file2
    file3
    Last edited by orphius (2013-07-09 08:11:53)

    Please remember to mark your thread as [Solved] by editing your first post and prepending it to the title.

  • Removing bracket from iMAC 24'' display for transportation

    Hi-
    I have a unique problem that I require some help. I need to transport the iMAC in a suitcase on an overseas trip and I need some help in removing the bracket. I do not want to experiment with it unless I know if it can be done.
    Could you please let me know if it can be removed so I can package it safely and reassemble at the destination.
    Thanks in advance!

    From my understanding of how the stand works, it is a removable part
    and to take it off requires a special tool; the tool is one usually supplied
    in the VESA kit, so once the VESA bracket is installed, the foot can
    be removed so it won't be hanging in the way.
    I'm not sure of the part number for the tool, but do know there is a
    specific VESA mount kit (doesn't include wall bracket, etc) for the
    iMac 24" and there is a mention of this detail in a fleeting fashion:
    "VESA Mount Adapter Kit for 24-inch iMac"
    With a tool in this kit, you can remove the iMac stand and attach
    the VESA Mount Adapter to the computer.
    Perhaps an authorized service technician can tell you what kind
    of tip the tool (if like a screwdriver) has on it, so you can buy one.
    [ Facts about VESA mount kit - 24" iMac ]
    The comments section in this page may be helpful.
    PS: There is a more specific discussions forum for Intel® Macs
    here, and maybe someone has addressed the VESA and foot
    removal issue there.

  • Regex: Remove Date from File Names Sitewide

    I'm trying to avoid  hundreds of 301 redirects across my site. I have two kinds of links that need a regex search string which will simply remove numbers that precede text within html files.
    The existing .html files are named with text only (e.g., name.html), whereas the .jpg files have the date and text (e.g., 130415name.jpg). But the new html engine I am using creates files named like the .jpg files (e.g., 130415name.html).
    I can strip the numbers out of file names in Name Munger (Strip Characters > Characters: 0123456789).
    Now I need a regex search string that will strip the same characters within the html files.
    The changes would look like this:
    1.
    Before:
    <ul>
    <li class="previous"> <a class="paginationLinks detailText" href="../content/090914name.html">Previous</a> </li>
    <li class="index"> <a href="../index_4.html" class="detailLinks detailText">Index</a> </li>
    <li class="next"> <a class="paginationLinks detailText" href="../content/090125name.html">Next</a> </li>
    </ul>
    After:
    <ul>
    <li class="previous"> <a class="paginationLinks detailText" href="../content/name.html">Previous</a> </li>
    <li class="index"> <a href="../index_4.html" class="detailLinks detailText">Index</a> </li>
    <li class="next"> <a class="paginationLinks detailText" href="../content/name.html">Next</a> </li>
    </ul>
    2.
    Before:
    onclick="window.location.href='content/020922name.html'"
    After:
    onclick="window.location.href='content/name.html'"
    What is the regex search string for these examples (any numbers preceding any letters preceding .html)?

    Set the Search option to Source Code
    In the Find field:
    (content/)\d{6}(\w+\.html)
    In the Replace field:
    $1$2
    Select the "Use regular expression" checkbox.

  • [solved]Removing applet from kdemod [my bad]

    Well I had a clean install of KDE mod, tried to install xfce, then E, rebooted broke X, tried to troubleshoot, gave up reinstalled, messed that up, next day, reinstalled again.....
    Went back to kde mod for now, but I have a question.
    While trying to add an application to the panel, I accidentally added an applet "System monitor". How in the heck do I remove it, as it isn't nearly as informative as conky, or anything else for that matter...
    Right clicking  and removing isn't there, when I right click on it.
    Thanks in advance, and btw I think I may have learned a thing or two during the last two re-installs, lol.
    Last edited by dunc4n (2008-03-14 07:34:37)

    It would have been nice if you wrote how you solved the problem: this way it will be a reference for future users with the same issue.
    futureguy "Cool, this guy had my same problem, let's see how he solved it!"
    you "Nevermind, I solved it!"
    futureguy "Damn!"
    Even if this was a trivial problem (as you probably forgot to unlock the panel), you can't really say.
    Last edited by carlocci (2008-03-14 16:13:53)

  • Delimited_hdr-=no in oracle 9i causes remove  header from file

    i am converting my output of reports into excel file i am using desformat=delimiter and delimited_hdr=no if i use this in my command line i got output without header and if i do delimited_hdr=yes then repetitive header displayed. how to overcome that problem i am using oracle 9i

    Hello All,
    I tried the resize procedure but the corruption doesn't cleared.
    SQL> ALTER DATABASE DATAFILE 'E:\SC\SC12.1\DATABASES\ORACLECONFIG\SYS1NM45.ORA' RESIZE 246 M;
    Database altered.
    SQL> ALTER DATABASE DATAFILE 'E:\SC\SC12.1\DATABASES\ORACLECONFIG\SYS1NM45.ORA' RESIZE 245 M;
    Database altered.
    SQL> ALTER DATABASE DATAFILE 'E:\SC\SC12.1\DATABASES\ORACLECONFIG\SYS1NM45.ORA' RESIZE 244 M;
    ALTER DATABASE DATAFILE 'E:\SC\SC12.1\DATABASES\ORACLECONFIG\SYS1NM45.ORA' RESIZE 244 M
    ERROR at line 1: ORA-03297: file contains used data beyond requested RESIZE value
    SQL> ALTER DATABASE DATAFILE 'E:\SC\SC12.1\DATABAES\ORACLECONFIG\SYS1NM45.ORA' RESIZE 400 M;
    Database altered.
    Can you please let me know how to recover corrupted Block or how to recover the corrupted file only.
    Thanks
    With Regards
    Hemant Joshi.

  • [solved] remove --MARK-- from everyting.log

    I use conky to print everything.log on my desktop. Every 20 minutes -- MARK -- appears. I don't know why, and there is probably a good reason for it. After a while, the only lines that appear are these lines. Can I remove this?
    Last edited by anadyr (2009-12-29 18:34:36)

    here's your solution
    http://bbs.archlinux.org/viewtopic.php?id=68092

  • Remove string from txt file

    Hello guys,
    I need some help. I have to remove some content of Tolerance "column" (see attach). The string which I wish to remove is "+/- 0s" and replace it with an empty string. I need to remove this for each row where "+/- 0s" appears.  
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    sample.txt ‏3 KB

    Hi Samoth,
    I dont know if I understood your requirement properly, but please check the attached snippet if it helps.
    If this does not satisfy your requirement, then please give some more details.
    Attachments:
    Remove string from txt file.png ‏21 KB

  • Remove LF characters from file names

    I have a folder full of files with filenames that contain LF character (ASCII code 10).  I want to use Automator's "Replace Text" funcion to remove these non printing characters from file names.  Is there a way to do it?
    If automator is not able to do this task, I will take a bash script or applescript solution as well...

    Take a look at: http://stackoverflow.com/questions/4417588/sed-command-to-fix-filenames-in-a-dir ectory
    (I changed  tr -d "\r\n" to tr -d "\n", but try both)
    for f in ~/Desktop/*
    do
        new="$(printf %s "$f" | tr -d "\n")"
        if [ "$f" != "$new" ]; then
            mv "$f" "$new"
        fi
    done

  • So I have a file on my desktop and I cannot open it, move it to a folder, or delete it from my mac. I dont know what it has in it, and that makes me suspicious. What can I do to remove this unremovable file from my computer? Is it a virus?

    So I have a file on my desktop and I cannot open it, move it to a folder, or delete it from my mac. I dont know what it has in it, and that makes me suspicious. What can I do to remove this unremovable file from my computer? Is it a virus?

    First, I would recommend repairing the hard drive with Disk Utility.
    If that doesn't fix the problem, there's a very dangerous command you can execute in the Terminal.  This is very hazardous, because a simple typo can result in very drastic consequences.  I have seen people erase their entire hard drive by putting a space in the wrong place!  So, please follow the directions I'm going to give you very carefully!
    Open the Terminal, which is found in the Utilities folder in the Applications folder.  In the Terminal, enter the following:
    sudo rm -f
    Make sure to put a space after the "-f"!  Then, drag the troublesome file from the Finder and drop it on the Terminal window.  That should insert the path to the file in the command.  Then go back to the Terminal and press return.  You will be asked for your password, and when you type it, nothing will be shown as a security measure.  Press return again after entering your password.  The file should be deleted.

Maybe you are looking for

  • Jtree, Double Click to open a file

    Here is what I have so far: tree.addMouseListener(new MouseAdapter(){             public void mouseClicked(MouseEvent evt){                 if (evt.getClickCount()==2){                     TreePath tp = tree                             .getClosestPat

  • Can you still buy Tiger?

    I want to upgrade to Tiger on a PowerBook G4 so it will be running the same system as other computers in the house. Can I still buy Tiger? All I can find in the Apple Store online is Leopard, and I don't want Leopard.

  • Problem in encrypting messages using wss4j

    Hi, I'm using wss4j for securing my service. I read a tutorial about wss4j handlers, I have done everything in the tutorial but there is problem while running the client. It seems that the Marlin class can not be instantiated, but I dont know why. th

  • Create a PDF contact sheet - What is the PDF preset?

    Hello When I create contact sheet, it creats a pdf but I don't understand what is the pdf preset. Is it for screen? print? where can I see or change it if at all? thanks shlomit

  • My name is displayed instead of my publishing company's name......

    My name is displayed instead of my publishing company's name for my books in iBookstore. I cannot find where to change it in iTunes Connect. Any suggestions (besides opening a ticket)?