| |

VerySource

 Forgot password?
 Register
Search
View: 972|Reply: 3

Two shell program questions, help to see

[Copy link]

5

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-16 19:20:01
| Show all posts |Read mode
1.Write a shell script to display the odd lines of a given file.
2. Write a shell script using a directory as input, if the input is null, use current directory as input. The routine is used to find all files with suffix ".c" and ".cpp", and then compare each other to check out whether there exist two files having the same contents: if exist, print out the corresponding names of these files.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-14 16:15:01
| Show all posts
#!/bin/sh
#for odd line
FLAG=1
for loop in `cat $1`
do
if [$FLAG -eq "1" ]; then
echo $loop
FLAG=0
else
FLAG=1
fi
done
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-14 21:15:01
| Show all posts
1:
sed -n'p;n' file
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-14 21:45:01
| Show all posts
1:
sed -n '1,${p;n}' file
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list