Ruby cannot find puts and other commands? [closed] - ruby

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I was attempting to do what I thought should be a very basic script as my first bit of ruby code. Perhaps someone can help me out with what's going on.
./delete_file.rb: line 3: puts: command not found
./delete_file.rb: line 4: auth_token: command not found
./delete_file.rb: line 6: puts: command not found
User1$ cat delete_file.rb
# /usr/bin/ruby
# Delete file script
puts "Enter current token"
auth_token = gets.chomp
puts "data goes here" + auth_token + "more data here"

first line of file should be:
#!/usr/bin/ruby

Related

File name too long bash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
i want to copy some files from ../soft to ../copu_new. The name of that tests are in ../sim/soft.txt.
I had en error : cp:cannot stat '../soft/file1.txt\file2.txt\file3.txt': File too long
Follow the code below:
input="../sim/soft.txt"
while read line
do
##to skip the first line of the file
a=$(tail -n +1)
##From string to table
for i in $a
do
table_soft[$i]="$i"
done
for i in "${tabke_soft[#]}"
do
cp ../soft/$i ../copy_new
done
done < $input
The file Soft.txt is :
###This all tests:
file1.txt
file2.txt
file3.txt
It's most likely the classic bash issue where trying to run an array through a for loop gives you all the content unless you wrap it in double quotes first. Try this..
a="$(tail -n +1)"

How to separate multiple parts of a line using ';' using shell script? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a '.GS3' file with multiple lines like this one:
0123456789 aaa.aaa3456
I want to separate it like this:
01234;56789 ;aaa.aaa;3456
I know the start and end of each part of the line. Is it possible to do this considering multiple lines? For example:
0123456789 aaa.aaa3456
aaaaabbbbbbbxxxxxxxwwww
Into
01234;56789 ;aaa.aaa;3456
aaaaa;bbbbbbb;xxxxxxx;wwww
.. but if it does have fixed lengths you can do it this way:
$ sed -r 's/^(.{5})(.{7})(.{7})(.{4})$/\1;\2;\3;\4/' test.txt
01234;56789 ;aaa.aaa;3456
aaaaa;bbbbbbb;xxxxxxx;wwww
I think .{5} is self explanatory. Due to the -r option the first group (.{5}) can be referenced by \1. It's a group due to ( and ).
The characters ^ and $ represent the beginning and ending of every line in the file test.txt.

How to remove leading / at each line a text file with sed Linux command [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
This is my text file and I want to remove every first line:
aaaa
bbbb/bbbb
/cccc/cccc
/Dddd/zzzz/wwww
.gggg
.oooo/sssss
/.vvvvv
!#%#/$%
How can I remove all first "/" from my text file?
I want the result text file to be like:
aaaa
bbbb/bbbb
cccc/cccc
Dddd/zzzz/wwww
.gggg
.oooo/sssss
.vvvvv
!#%#/$%
if it's any help, I'm using sed command.
sed can be instructed to replace the first / of each line with nothing:
sed 's_^/__' 'my text file name'

ruby Unexpected keyword else error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have this ruby program to parse a CSV file. I am missing a endif somewhere and I cannot figure out.
require 'csv'
prevrow=nil
newarray=Array.new
CSV.foreach("\\\\192.168.0.1\\fe18cb0618cabd41\\ninjatrader\\uniqueside.csv", col_sep: ',') do |row|
if(prevrow==nil)
# do nothing
newarray<<row
prevrow=row
elsif (prevrow!=nil and row[0]!=prevrow[0] )
# do something
newarray<<row
prevrow=row
##count=1
elsif(prevrow!=nil and row[0]=prevrow[0] and ##count<4)
puts "new date"
newarray<<row
prevrow=row
##count++
end
end
removesamedirctiontop4.rb:23: syntax error, unexpected keyword_else
removesamedirctiontop4.rb:27: syntax error, unexpected end-of-input, expecting keyword_end
#count++ is not valid ruby. The final "plus" is expecting another parameter and thinks it's on the next line, so the line ends up being interpreted as...
`#count + +end`
So you have an invalid statement and you lose an end.
Change the offending line to
#count += 1

Substitution in %x command in Ruby [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a Ruby script to unzip a file where each pass through the %x{unzip } will have a different file name.
I have been successful getting
%x{unzip FILENAME.ZIP} to unzip the contents of FILENAME.ZIP
However, I want to be able to pass in the name of the file to unzip.
I've tried variations of
filename = "CONSTANT+variable+"NEXT_CONSTANT.ZIP"
%x{${filename}}
and I have been unable to get the %x to let me construct a filename that I want to unzip.
You can do it the same way you'd do it in a double-quoted string: #{filename}.
filename = "my_files.zip"
%x{unzip #{filename}}

Resources