Ubuntu :: Bash Script - Removing Windows Return Characters

Sep 1, 2010

I've got a basic script, which parses data from a text file and performs actions based on that data. Here is my code:

Code:
dsrc="/home/russellm/sites/"
ddst="/home/russellm/othersites/"
while read SiteID
do
if [[ ! -d "$ddst${SiteID:0:1}" ]]
then
mkdir "$ddst${SiteID:0:1}"
fi
mv "$dsrc${SiteID:0:1}/${SiteID%*}" "$ddst${SiteID:0:1}/" | tr -d '
' done < sites.txt

The text file came from a windows system, and contains those return characters (). I 'could' just run the whole thing through tr and then run the script on the new data file, but I'm looking for a more elegant solution. As the code above shows, I'm trying to pipe the mv command though tr in order to remove the return character - but it's not working. I can't get this to work with sed either, so I know I'm doing something wrong. I also tried to remove it using ${SiteID%} - but that also failed. The characters don't show up in an echo, just when executing a command.

Output example (emphasis mine):
Code:
mv: cannot stat `/home/russellm/sites/B/B23467324
': No such file or directory
I'm tempted to just convert the file once and call it a day, but you know what it's like. To be honest, I'm starting to suspect that there are no return characters, and that I'm going about this wrong.

View 4 Replies


ADVERTISEMENT

General :: Bash - Using Find Or Grep To Locate Filenames With Accented Characters From A Different Encoding System (Windows)

Dec 6, 2010

I tried to tag late onto a question similar to mine on stackoverflow (Find Non-UTF8 Filenames on Linux File System) to elicit further replies, with no luck so far, so here goes again... I have the same problem as the OP in the link above and convmv is a great tool to fix one's own filesystem. My question is therefore academic, but I find it unsatisfactory (in fact I can't believe) that 'find' is not able to find non standard ascii characters.

Is there anyone out there that would know what combination of options to use to find filenames that contain non standard characters on what seems to be a unicode FS, in my case the characters seem to be 8bits extended ascii rather than unicode, the files come from a Windows machine (iso-8859-1) and I regularly need to fetch them. I'd love to see how find and/or grep can do the same as convmv.

[Code]....

View 2 Replies View Related

General :: Removing The Escape Characters From GNU Screen's Screenlog.%n?

Jan 22, 2010

Is it possible to remove the ESC sequences in GNU Screen's output file? Things such as colours, tabs and other escape characters make their way into the log files and become difficult to decipher.

I've tried Dr. Google & Co. as well as reading the manual, but haven't been able to find anything suitable.Perhaps I've overlooked something?

View 3 Replies View Related

General :: Return Part Of A String In Bash?

Mar 20, 2011

I would like to return the last part of a string in an array of strings in bash.

The array contains in each position the content below:

Code:
a.b.c
a.d.f
a
a.d

[Code].....

View 5 Replies View Related

Programming :: BASH Read File Once Then Return To Top?

Aug 8, 2010

I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:

Code:

"COLORS.JPG:red,orange,yellow,green,"
(Returning)
red

[code]....

single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:

KEYWORDS:

[ ]red
[ ]orange
[ ]yellow

[code]....

Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.

View 14 Replies View Related

Ubuntu :: Bash - Shift Ascii Characters Up Or Down One

Feb 20, 2010

Say you wanted to write a bash script for "hello world" but the characters were shifted up or down by one.

How would one go about this?

Example:

Code:

Code:

View 5 Replies View Related

Programming :: Termios Programming - Without Removing Carriage Return / Enter Key

Jun 30, 2010

I trying to write a UART(interfacing of serial devices) to linux machine but after I execute the following code to receive data I need to enter key (carriage return).... but I don't want to remove carriage return/enter key

[Code]....

View 13 Replies View Related

General :: Split A String Into Array In Bash Return Wrong Size?

Mar 21, 2011

I'm trying to split a string, to later iterate using a for loop like

Code:
for (( i=0; i<5; i++))

But, my script returns an array with the size 1.

Here's the script:

Code:
aver=$(grep "avg" A.txt | awk '{ print $2 }');
a=$(echo $aver | tr " " "
");

[Code]....

View 2 Replies View Related

General :: Bash Prompt Loses Characters?

Apr 17, 2011

After writing a new prompt for Bash, I noticed that one character of my commands were being lost when it wrapped to the new line. Here is an image of the example (I typed 1234567890 over and over):

Here is my $PS1

PS1="
[[e[0;90m]d [e[0m]] [[e[0;90m]$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, $(/usr/bin/du -sh | cut -f1)[e[0m]
[[e[0;36m]#[e[0m]] [e[0;95m]u[e[0;90m]@[e[1;92m]h[e[0m]: [e[1;34m]w [e[1;30m]$[e[0m] "

What have I done wrong?

View 1 Replies View Related

Programming :: Md5sum Bash Script With Escaped Characters?

Apr 15, 2010

I created a file holding all the md5 values of my files to find duplicates as follows: find /mnt -type f -print0 | xargs -0 md5sum >> ~/home.md5

I then tried to find duplicates and do ls -l on the result in such way: cat ~/home.md5 | awk '{print $1}' | sort | uniq -c | sort -nr | awk '{print $2}' | head -n 10 > ~/top10.md5

Now I attempted to do an ls -l on the files using the command: for i in `cat ~/top10.md5`;do grep $i ~/home.md5 | while read checksum path; do echo "`echo $(printf '%q' "${path}")`" | xargs ls -l; done; done

This works well on most files, however it does not work when filenames have special letters in them that gets escaped such letters with accent etc. These become for examle 303.

Are there any ways I can use the escaped 303 strings with path names, or any better way I can do this?

View 2 Replies View Related

Programming :: Bash - Test If First 2 Characters In A Filename Are Numbers?

Oct 21, 2010

I have a directory with files like this:

Code:

And what I'd like is to have the files renamed like this:

Code:

How could I code it so that it removes the numerical part of the filename (at the beginning), even with different patterns (like the 01 - artist vs the 01-artist)?

View 8 Replies View Related

Programming :: Bash - Automatically Build A Set Of Packages And Redirect Output Into Logs - Failed Make Should Return A Non-zero Value

Jun 27, 2011

I have a set of bash scripts that I'm running that automatically build a set of packages for me and redirect their output into logs. Basically, I have a bunch of lines that are something like this: ${CONFIGURE_DIR}/configure &> ${LOG_DIR}/log or cd ${CONFIGURE_DIR} && make &> ${LOG_DIR}/log, etc.

This is supposed to make the entire process silent. However, sometimes with some packages some output leaks to my console (either stdout or stderr). I'm thinking that maybe the configure scripts/make are executing commands within new shell instances that don't inherit my redirect, or something to that effect.

Another reason for thinking this is that in another part of my script I detect errors when running make by testing with "if [ $? -ne 0 ]", and if the redirect leaks to my console and also the leaked output indicates that the build failed ("make: Error" and so on), then my $? test fails (i.e., it thinks that $? == 0, whereas a failed make should return a non-zero value). It's as if my original script can't "see" the results from child commands executed from later scripts.

View 1 Replies View Related

General :: Bash : Pass Command Line Arguments Containing Special Characters?

Jul 14, 2010

I've written myself a linux program "program" that does something with a regular expression. I want to call the program in the bash shell and pass that regular expression as a command line argument to the program(there are also other command line arguments). A typical regular expression looks like "[abc]_[x|y]".Unfortunately the characters [, ], and | are special characters in bash. Thus, calling "program [abc]_[x|y] anotheragument" doesn't work. Is there a way to pass the expression by using some sort of escape characters or quotation marks etc.?

(Calling program "[abc]_[x|y] anotheragument" isn't working either, because it interprets the two arguments as one.)

View 7 Replies View Related

General :: Bash: How To Pass Command Line Arguments Containing Special Characters

Jun 24, 2011

I've written myself a linux program "program" that does something with a regular expression. I want to call the program in the bash shell and pass that regular expression as a command line argument to the program (there are also other command line arguments). A typical regular expression looks like "[abc]_[x|y]". Unfortunately the characters [, ], and | are special characters in bash. Thus, calling "program [abc]_[x|y] anotheragument" doesn't work. Is there a way to pass the expression by using some sort of escape characters or quotation marks etc.? (Calling program "[abc]_[x|y] anotheragument" isn't working either, because it interprets the two arguments as one.)

View 8 Replies View Related

General :: Bash Script To Parse A File To Get A Set Of Line Between A Specific Characters?

Dec 23, 2010

I have a log file that contains information like this:

----------------------------
r11141 | prasath-palani | 2010-12-23 16:21:24 +0530 (Thu, 23 Dec 2010) | 1 line
Changed paths:
M /projects/
M /projects/

[code]....

what i need is, i need to copy the data given between the "---" to seperate files, for, e.g. the first set of data between the "---" should be in one file and another set of data in another file.

View 5 Replies View Related

Programming :: Bash Removing String From File?

Aug 7, 2010

I am trying to remove everything before my string code...

View 9 Replies View Related

Ubuntu :: Can't Return To Windows 7

Mar 22, 2010

i tried to install brug theme so i cant return to windows 7 which files should i paste here.

when i click to windows 7 option in grub boot menu it just returns me "GRUB"

View 9 Replies View Related

Programming :: Change A Line In A File Code - Sed Special Characters Bash Script

Jan 26, 2011

I'm having issue when trying to change a line in a file

[Code]....

View 1 Replies View Related

General :: Bash Scripting - Removing Strings From MP3 Filenames

Oct 5, 2010

I've been surfing and searching the net quit a while now to make my own script, but I haven't been really successful ever since I want to make a script which can remove strings from my mp3 collection (file names).

For example:
Code:
101-bob_sinclar_feat_sean_paul-tik_tok_(radio_edit).mp3 --> bob_sinclar_feat_sean_paul-tik_tok_(radio_edit).mp3
10-Young Jeezy-Lose My Mind (78 Bpm) (Repack).mp3 --> young_jeezy-lose_my_mind.mp3

Now the problem is how can I remove the strings like:
101 & 10 (dynamic)
(%%% Bpm) (dynamic)
(Repack) (static)

View 11 Replies View Related

Programming :: Bash Output With Timestamp Removing Duplicates

Nov 20, 2010

I'm writing a bash script to auto run on boot in Tinycore.

This is a watered down version.

Code:

I need it to either not add the time stamp if the awk finds a duplicate or write over the time with the new time if awk finds a duplicate.

BTW this is all pretty much cut-and-paste scripting so please feel free to comment if you know a more elegant way.

View 3 Replies View Related

Ubuntu Installation :: Can't Return To Windows?

Sep 17, 2010

I'm a italian boy that have a problem with ubuntu. I install ubuntu on my netbook with wubi but now I can't return on windows. When I restar my pc i see GNU GRUB version 1.98-1ubuntu6

I select the part for to go in XP Windows NT/2000/XP (loader) (on/der/sda1) but I see the black windows with the script error: unknows command 'drivemap' Try (hd0,0): NTFS5: And I return to black windows that allows me to choose the part Ubuntu.

View 2 Replies View Related

General :: Removing Subdirectorys And Only Working With Files (Bash Cookbook 5.8)?

Jul 6, 2010

The Cookbook gives us

for FN in $*
do
echo changing %FN
chmod 0750
done

but that changes all. how can I change all files but subdirectorys? I was thinking of something likels -l | grep -v ^d but can't get it to work. I'm still learning about variables and how to use them. thanks in advance for your Patients.

View 2 Replies View Related

Ubuntu :: Installed After Windows7 - Can't Return To Windows 7

Oct 16, 2010

I have a Asus EEE PC 1005HA netbook, which I use with Windows 7. I've been abroad for the last 2 weeks, and when I came back I found out my younger brother has installed Ubuntu on it.

When I asked him he told me it's no problem, and he didn't overwrite Windows, just installed on another partition.

However, I'm trying to get back to my original operating system and I have no idea how. Obviously, he has none either as he is just an impulsive 15 year old.

I'd like to either uninstall ubuntu and return to my windows OS, or just choose at boot time which OS I want to access (I don't really mind having a linux onboard, I assume it has it's merits).

View 7 Replies View Related

Ubuntu :: Hibernate For A Brief Trip To Windows And Return?

Nov 22, 2010

First of all, I searched the forums but I couldn't find anything- I don't want to be the poster who posts something that's been solved 14 times already Anyway, primary question first and then "why" below- I was wondering if there was a quick way to hibernate Ubuntu to Swap -> boot to Windows 7 and work -> Hibernate Windows 7 -> boot to Ubuntu and work, repeat until Windows glitches

I have, new Acer Aspire:
i3 370M
4GB RAM
640GB HDD as follows, from inside to outside:
X GB 3 Primary Windows partitions, 125 GB unnallocated, 50GB /home, 6 GB .boot, 4 GB SWAP

Ok, why would I want to do that? I ask because while Ubuntu boots fast at just under 1 minute at the end of my hard drive (90Mbps, I had it install from "end" when I partitioned the boot file), Windows boots slowly at about 2.5 minutes on the inside of my drive (23sh Mbps). To be able to switch between them would be useful for iTunes, ProEngineer, Matlab, and other stuff that is Windows based. Windows boots much faster from hibernation. I love Ubuntu, the speed and simplicity and the actual FRIENDLY atmosphere (what a concept WINDOWS) But I find myself needing to do some quick editing in Windows, then I can go back to my business on Ubuntu. Is there some kind of selective boot managing like GRUB that I can bring up after telling one to hibernate? Because once on SWAP, it should hold relatively indefinitely until I return, right??

Any ideas??? It sounds like some clever Terminal coding could manage the Linux side of the booting, but Windows might have to be tricked into a selective boot..

View 9 Replies View Related

Ubuntu :: All Characters In Windows Became 口?

Dec 23, 2010

Just now, after I open my computer, all of sudden, all the characters in windows and menus became little rectangles. What shall I do?

View 9 Replies View Related

Ubuntu :: Delete All ASCII Characters In File - Leave Chinese Characters Only

Jul 8, 2011

What command could I use in terminal to delete all ASCII characters? That is, delete a-z, A-Z, 0-9, and all punctuation? I have a file containing Chinese characters, and I want to remove everything else and leave just the Chinese.

I can use grep to leave only the lines that have Chinese in them, but this still leaves a lot of non-Chinese stuff on those lines. Does anyone know how I could actually remove everything that isn't Chinese?

View 4 Replies View Related

General :: Write Special Characters (like |, ~, Alt, +, 124 In Windows)?

Apr 15, 2009

I've always been connecting to linux machine from windows computer, using putty.

Now the situation changed and I have a question:

How the hell can I write special characters (like | ~ Alt + 124 in Windows)?

View 4 Replies View Related

Ubuntu :: Removing Windows From Grub

Oct 11, 2010

I had windows 7 installed in my 4th drive and windows vista as my boot drive. I formatted my windows 7 drive using vista and installed ubuntu 10.04 in its place. But still, when i update grub it shows windows 7 as one of the operating systems and my vista OS has been renamed as Windows 7. Please help. How can I remove windows 7 from the list, while i update grub.

View 3 Replies View Related

Ubuntu :: Windows Fails To Work After Removing?

May 9, 2010

I have one laptop running on ubuntu and one computer running on ubuntu.....once i removed ubuntu from my laptop....and installed windows on my laptop but it didn't work as it should work. It used to crash too often. Then i removed windows and put ubuntu on my laptop.. but now i want to put a new hard disk in my computer....but now i want to run both windows and ubuntu.....i just want to ask that does ubuntu leave any strains on my hard disk when i remove it.....and is that the reason windows doesn't work properly

View 6 Replies View Related

Ubuntu :: Booting After Removing Windows 7 Trial?

Jun 12, 2010

I have a problem booting ubuntu 9.10 after removing a disk drive that had windows 7 on it from my PC. Below is a run down of what happened.My system is MSI based MB with 3 IDE drives and DVD-writer on Primary and Secondary IDE channels.The MB also has a FASTTRACK SATA/IDE controller that I occasionally use to attach another disk for trial/backup purposes. (main backup is to external USB storage)For some time I have DUAL booted with grub2 with ubuntu 9.10 and windows XP all fine and no problems. Use ubuntu as its quick and easy on my old PC. XP for some legacy apps.As I had a spare IDE drive I thought I'd give a Windows 7 a trial. The Drive is attached to the FASTTRACK IDE controller and windows 7 installed with NO OTHER drives attached.

All OK so far!Reattached my other drives and could boot into ubuntu/XP as required. Ran sudo update-grub which found new windows 7 Ok! So for the last month I was happily play/using all 3 OS booting from grub2 loader as required.Windows 7 30 day trail has now expired so no longer of any use to me. So I decided to remove windows 7Here's what I did:..........1st: Just unplugged the disk drive with windows 7 on it! XP boots OK but ubuntu fails to boot! 2nd: Re-attached the windows 7 drive and wiped with ubuntu disk utilityRe-ran sudo update-grub windows 7 no-longer on grub2 menu! Reboot OK windows 7 no-longer on grub2 menu ubuntu and XP boot ok. Remove (empty)windows 7 drive again and ubuntu fails to boot

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved