Questions on bash

Cixy 2004-10-14 11:23:53
Met some problems on bash programing:
1. how to read a line from file and save it into a variable?
2. how to reserve a string?
3. does reg exp support number caculation? how?
4. how to return value in a function and how to retrieve it outside function?
5. how to format the output string?

Thanks for your reply!
...全文
159 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cixy 2004-10-18
  • 打赏
  • 举报
回复
唉,还是去UNIX站点寻求帮助吧,谢谢两位了
gettext 2004-10-15
  • 打赏
  • 举报
回复
用awk更合适。man awk
Cixy 2004-10-15
  • 打赏
  • 举报
回复
man awk... too many to read... I have to say my english is not good(use english just because no chinese ime installed on the lab pc)

so... could you please give a clear answer for my questions?

Thanks,
pacman2000 2004-10-14
  • 打赏
  • 举报
回复
1. read a < t.txt
2. ???
3. i=`expr $1 + 1` ?
4. man bash , see FUNCTIONS
5. printf
Cixy 2004-10-14
  • 打赏
  • 举报
回复
Thanks pacman and mahongxi,

pacman,
I tried your code, but only the first line was successfully read.
In fact in question 1, I want to write an iterator to go through the whole file line by line.
In question 2, I want to reverse a string (sorry for my typo :P)

mahongxi
In your method, how to count the number of lines in a file?

Thanks again and appreciate for you reply.
mahongxi 2004-10-14
  • 打赏
  • 举报
回复
1.
$line_str=$(sed "2 p" -n t.txt) 2 is line number

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧