[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)

Similar Messages

  • 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] 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.

  • [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)

  • How do I remove apps from the Creative Cloud list

    I get reminders of old CC apps that I don't have installed att my mac.
    Old CC programs that I have removed from my mac.
    How can I remove the from the CC apps list?

    I found the solution in the community
    Solution 1
    Mac OS: Run the uninstaller in the Applications/Utilities/Adobe Installers folder to remove the program listed as up-to-date.
    Windows: Use the Programs And Features Control Panel to remove the program listed as up-to-date.

  • 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

  • Data read from Memory use - ranked list

    Dear Experts,
    I am trying to read data from memory use -ranked list.
    In general we use function pool to read the data but in case if we should read the data from a class can we do it.
    {O:267}-IF_PT_HRS_D_IF~IM_CONTRACT_TES[1]-TES
    in the above class in TES table we have data , we have to read data from TES .
    In memory use ranked list it is like below
    {O:451*\CLASS=CL_PT_HRS_IF}
    Object
    Regards,
    Kartheek.

    Philip
    This one is really tricky. Display value just shows the rank but it would hold the actual value when you try to do calculations.
    We have had similar problem but it was not related to ranking.
    One Simple approach could be
    Make them use Wrokbooks and do this calculation by using a SUM formula in Excel. Excel will consider whta is being displayed as a value for that cell
    One far complicated solution is you can use the Olympic ranks and Do your sum in a Macro.
    What I mean is if you get the last rank to be 10 then you can write your program to do the sum as
    1098765432+1.
    This approach could be taken only if they are OK with Olympic ranking.
    Edited by: Abhijit N on Dec 10, 2008 10:19 PM

  • Remove words from Swype?

    Hello,
    Somehow I managed to get some words in Swype and I want to remove them.
    How do I remove them from my phones list of words?
    Thanks,
    VeePee
    Nokia 3395
    Nokia 6600
    Nokia N95 8GB
    Nokia N8 (Anna)
    Nokia Lumia 930
    Solved!
    Go to Solution.

    Refer this ..
    ...and Some more tips here ..

  • RE: HELP !!! ACCIDENTALLY REMOVED "EVERYONE" FROM MACINTOSH HD USER LIST

    Last night, I looked at "Get Info" for the "Macintosh HD"
    At the very bottom of the window are listed Permissions, that consisted of (1) Owner, (2) Admin, (3)Everyone.
    I had the idea that if I REMOVED "Everyone" by selecting it and hitting "-", I could better secure access to the "Macintosh HD".
    Well, now the G5 starts its boot up routine and stalls at the gray screen with pinwheel spinning.
    1. I tried purging the P-RAM... no change.
    2. I tried doing a "Safe Boot", didn't do anything, couldn't get it to boot up beyond gray screen. Used COMMAND SHIFTV saw boot routine, but stalled at the foollowing line which repeats over and over:
    "Jun 13 14:03:58 NJ-Computer com.apple launchd{1} (com.apple.mDNSRespnder {1991):postix_spawnp("/usr?sbin/mDNSResponder",...):No such file or directory"
    3. Booted up from Leopard CD, and ran "Verify Disk" with the result message that "the volume Macintosh HD appears to be OK"
    4. Ran "Repair Disk" with the result message that "the volume Macintosh HD appears to be OK"
    5. Tried to run "Verify Permissions" with the result message "Error: The underlying task reported failure on exit. Permission verification complete"
    6. Tried to run "Repair Permissions" with the result message "Error: The underlying task reported failure on exit. Permission verification complete"
    I assume that my stupidly removing "Everyone" from the permissions list of "Macintosh HD" is the cause.
    HELP !!!! IS there an easy way to restore the Permissions to where they were before ????
    PLEASE HELP.
    THANKS !!!!

    HELP . . .
    i am having the same problem only i deleted "Administrator". I tired almost everything the original poster did and nothing is helping.
    i am in the process of a safe boot but nothing seems to be happening
    i tired Kiraly's suggestion to no avail. after i type in the commands do i restart? cause that's what i did and it did not work. I have a macbook (a white one), is the command different for a macbook?
    Please help if you can!
    Message was edited by: Britainy

  • Remove entries from the network services list?

    So I used to run Missing Sync so I could get my crappy Motorola Q to (sorta) talk to my Mac. Ditched it, got an iPhone. Removed it from my system.
    But in the Network system preferences pane, in the lefthand column that lists all of my "services," there are 37 duplicate entries, all created by Missing Sync - they're labeled "Missing Sync for Windows Mobile (en3)".
    And I cannot delete any of them. Selecting one and clicking on the remove button does nothing. I can rename them to whatever I like. I can disable them, which grays them out...but they're still there.
    Does anyone know how I can purge them from my system?
    Thanks.

    Hi,
    Just wondering if you were able to solve the problem because I have the exact same problem! Tried installing and un-installing the program a gazillion times; all in vain.
    Also used Pacifist to figure out all the places the program was throwing its crap and took all that stuff out ... still can't get rid of those network entries ...
    Any help would be greatly appreciate!
    Thanks!
    - Archit

  • How do I remove updates from the "all updates" list?

    Hello, say I have been getting updates for Windows 7, and I fully migrated to Windows 8, how do I get to remove the updates for Windows 7 from the "All Updates" list within WSUS? I have tried de-selecting the Windows 7 product from the p roducts
    and classification option, and I have tried runing the clean-up wizard, but they are not getting removed. Deleting the database and reinstalling WSUS can't be the only option....

    Uh... no... they weren't. No such concept exists. However, if you have an Automatic Approval rule configured on your WSUS server, that could account for such an action.
    And all of that is aside from why these updates were imported from the Online Catalog in the first place, and not just synchronized normally like other updates.
    What do you mean no such concept exist? They were approved by an admin, no one said anything about getting them imported, you are assuming these things, and normal sync was conducted.
    Okay, let's clear up some logical impossibilities here. If the Server Cleanup Wizard deleted files, then the updates were DECLINED. Then the downstream servers WILL synchronize those declines, and the updates will be DECLINED
    on the downstream servers.
    Yes, that is theoretically how it’s supposed to work, but it does not, for example, my upstream server is showing 223 updates for FEP 2010, but my downstream server is showing 239 updates out of which 21 are invalid software updates.
    This statement is logically inconsistent on a number of levels:
    First, as noted, if the files were deleted, then the updates were declined on the upstream server, so they should now be declined on the downstream server.
    Second, I have no idea what you mean by "red X representing an invalid software update". I'm not familiar with any such icon. Can you provide a screenshot?
    Third, the servers are not "still getting the metadata". They get it ONCE. The day it arrives in the environment. After that, it's there FOREVER... unless deleted by the Server Cleanup Wizard.
    As I already explained, theoretically the files should be synced up, but they don't and when I say that they are represented by a red X I am referring to the Microsoft's Technical Reference for the Icons Used for Software Updates which you can find here
    http://technet.microsoft.com/en-us/library/hh848254.aspx
    So here is the thing, you are saying that the metadata is there forever, but is it? I mean if the server cleanup gets rid of it that means it’s not there forever, right? Maybe I am missing something? As a side note, I did run the server cleanup wizard, and
    it did not remove it since the icons with the red X's are still there...
    So first question: Have you used the Server Cleanup Wizard on the downstream servers?
    Yes, and it did not help. I am still seeing bad updates, as these ones for example –
    Not possible, except by declining the update on the upstream server. Which should have already replicated.
    Declining updates does not help me in this scenario for postdated KB's, only for the ones going forward.
    I'll still need to figure out what you're talking about here, as I have absolutely no idea about these indicators.
    Please refer to Microsoft's reference -
    http://technet.microsoft.com/en-us/library/hh848254.aspx
    No, actually. :-//
    Does it now? :P

  • Remove word from spell_checker

    The built in deault spell-checker (OS X 10.7.2) seems to think the word "Adrain" is correctly spelled.  How can I remove this word from it's dictionary?  Note this is NOT a question about personal dictionary additions or learned words.  I do not see an "Unlearn Spelling" option for this word.  Also, I am UNIX savy so directions that involve manually editing files would be fine.

    I am running 10.6.8 and this screen shot shows where my LocalDictionary is located.
    It is Homefolder\Library\Spelling\LocalDictionary.
    Back when I was running Tiger, that file was called something else, and I used TextEdit to change it.
    I do not know if SnowLeopard works same.
    I just tested it, and I'd say that it works same, that is I edited it with TextEdit.
    Message was edited by: db24401
    Message was edited by: db24401

  • How can I remove Facebook from the iPhoto source list?

    Lately when I use iPhoto it will not let me quit and I have to force quit. I recently moved to college where there are several separate internet routers. I realized I still had iPhoto sharing turned on from using it at home and thought that might be messing it up, but even after I turn off sharing it will not let me quit. I think it is a problem with Facebook because it asks, "still syncing would you like to stop and quit?" whenever I try to quit the program. I would like to just remove Facebook from my source list, but I can't figure out how. It used to ask me to sign in to Facebook if I wanted to upload pictures but now it doesn't so I have no idea how to make it quit syncing.

    I found the solution in the community
    Solution 1
    Mac OS: Run the uninstaller in the Applications/Utilities/Adobe Installers folder to remove the program listed as up-to-date.
    Windows: Use the Programs And Features Control Panel to remove the program listed as up-to-date.

  • Can't Create PDF "from file" using any MS Office files

    Acrobat 8.1.1 Pro. (OS = XP), as part of the CS3 premium edition.
    I can no longer get Acrobat to recognize any of the MS Office applications extensions (.doc, .ppt, etc...) for use with either Create PDF "From File" or when using the Combine Files feature to Merge or Package. The extensions are no longer even listed as an option in the dialog box, or in the Preference settings under "Convert to PDF".
    FYI- I can still use the PDF Maker functionality from within the MS Office application to create a PDF.
    Any Idea what could have happened, or more importantly how to fix?
    ***Update***
    I have re-installed the Acrobat 8 application, and the problem still exists.
    I'm truly puzzled.

    I get this with my PC and I ran detect-repair and reinstalled. Some PDF's I can open and other's I cannot. I can send the email to a cohort and they can open fine.
    "Can't create file: Right-click the folder you want to create the file in and then click Properties on the shortcut menu to check your permissions for the folder"
    Any ideas would be great.
    Thanks!

Maybe you are looking for

  • Transaction F110 - Automatic Payment

    Hi ! In Transaction F110 - Automatic Payment when i execute a proposal for payment of 'XXX' vendor, then in the execute of the next proposal vendor XXX won't participate despite i enter vendor XXX in the range of vendor select option field. Is in SAP

  • ISBC Replication from CRM 2007 to R/3 4.7

    Dear Experts We are working on internet sales where we have to  Replicate Transaction type (ISBC)  from CRM2007 to R/3 4.7 . for further execution.Is it possibe to replicate to R/3 or do i need to create new transaction type i.e ISBC in R/3. We have

  • Change string value by adding a transaction key in T156

    Hello expert, My client want to add the transaction key BSX in the string value used for the code movement 261 k (good issue of supplier consignment stock). SAP Active Global Support respond that changes of value string for standard movement types ar

  • Getting error in calling Java Script function in HTMLB page

    Hi   I am having a button in HTMLB page which calls the Java Script function for click event.I have included the Java Script in the script folder of the application. I am calling the function present in JS like this, <SCRIPT src="portalsdc.js"></SCRI

  • Updates stopping halfway through

    Hey everyone, I'm trying to get the "GarageBand Instruments and Apple Loops" update for GarageBand which is 1.2 gb all together. The problem that I'm getting is that the update quits halfway through and when I try to do the update again it starts ove